npm build not failing properly - javascript

My package.json
"scripts": {
"lint": "eslint src tools test",
"test": "npm run lint && mocha --compilers js:babel/register",
"clean": "babel-node --eval \"require('./tools/clean')().catch(err => console.error(err.stack))\"",
"build": "babel-node --eval \"require('./tools/build')().catch(err => console.error(err.stack))\"",
"start": "babel-node --eval \"require('./tools/start')().catch(err => console.error(err.stack))\"",
"deploy": "babel-node --eval \"require('./tools/deploy')().catch(err => console.error(err.stack))\""
}
When I do
npm run build
having syntax error in any file of the application. I can see the console error output in console but the build itself returns exit code 0. How can I fail the whole build?
(throw - not working)

Related

I can't make a commit and push

I can't commit and push my code in git.
What i do:
git add .
git commit -m "init commit"
What i get:
after that nothing works for me, I can't click anything.
My package.json
"devDependencies": {
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"prettier": "^2.8.1",
}
scripts": {
"start": "cross-env PORT=3006 react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-scripts test --watchAll",
"test:ci": "cross-env CI=true react-scripts test",
"eslint": "eslint -c .eslintrc.js --ext .ts src/ --max-warnings=0",
"eslint:fix": "npm run eslint -- --fix",
"prepare": "husky install"
},
My .lintstagedrc
{
"*.{ts,tsx}": "npm run eslint",
"*.test.{ts,tsx}": "npm run test:ci"
}
npm install does not help(
You tests are being run in watch mode, as people have said in the comments.
The test:ci command you have is intended to disable watching by creating the CI environment variable, but you're probably not running on the platform that command was written for.
The simplest solution is to add the --watchAll=false command line option in the test:ci script:
"test:ci": "cross-env CI=true react-scripts --watchAll=false test",
Ref: https://create-react-app.dev/docs/running-tests/#on-your-own-environment
PS: I'm not familiar with cross-env, but that reference shows ways you might configure test:ci on various platforms.

How to run server only after webpack completes bundling bundles?

"scripts": {
"start": "node server.js",
"build": "webpack"
},
how to run npm run build first and then npm start in a single command?
"scripts": {
"start": "node server.js",
"build": "webpack",
"start-dev" : "npm run build && npm run start"
},
I tried the command npm run start-dev. But only webpack is being compiled. The server isn't running.
I don't know why that doesn't work, but, anyway, you can try this:
"scripts": {
"start": "node server.js",
"build": "webpack",
"start-dev" : "webpack && node server.js"
}
npm i npm-run-all
this package never run into issue. You can add as many as commands
"dev:start": "npm-run-all build start",

setting start scripts in package.json

locally, i start my app using the following commands:
cd react-web
sudo npm run postinstall
export REACT_APP_CUSTOMER_ENVIRONMENT=envvariable
npm start
So, now i want to push this live through heroku. BUT, i need to set the start scripts in my package.json
so i have two package.json, one in the root directory, and one in react-web.
in the root directory, i wrote this start-script:
"scripts": {
"test-web": "cd react-web && npm test && cd ..",
"test": "npm run test-web",
"start": "cd react-web && export REACT_APP_CUSTOMER_ENVIRONMENT=gianlucaherokutest && npm start"
},
and in the react-web package.json, this:
"scripts": {
"start": "node checkEnvironmentForBuild && react-app-rewired start",
"build": "node checkEnvironmentForBuild && react-app-rewired build",
"deploy": "aws s3 sync build/ s3://YOUR_S3_DEPLOY_BUCKET_NAME --delete",
"postdeploy": "aws cloudfront create-invalidation --distribution-id YOUR_CF_DISTRIBUTION_ID --paths '/*' && aws cloudfront create-invalidation --distribution-id YOUR_WWW_CF_DISTRIBUTION_ID --paths '/*'",
"postinstall": "npm link ../shared",
"test": "node checkEnvironmentForBuild && react-app-rewired test",
"eject": "react-scripts eject"
},
can someone give me some advice on why it isn't working? When I run the app using everything above, it gives me this error:
2021-04-19T21:12:11.796818+00:00 app[web.1]: FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
any ideas?

How to run "npm start" run forever

when the status is online i am running the port on 8014 its still not running
when i use pm2 start tools/srcServer.js
"scripts": {
"prestart": "babel-node tools/startMessage.js",
"start": "npm-run-all --parallel test:watch open:src",
"open:src": "babel-node tools/srcServer.js",
"test": "mocha --reporter progress tools/testSetup.js \"src/**/*.test.js\"",
"test:watch": "npm run test -- --watch",
"clean-dist": "npm run remove-dist && mkdir dist",
"remove-dist": "node_modules/.bin/rimraf ./dist",
"build:html": "babel-node tools/buildHtml.js",
"prebuild": "npm-run-all clean-dist test build:html",
"build": "babel-node tools/build.js",
"postbuild": "babel-node tools/distServer.js"
}
I am running the node with npm start I need to run the node to run run the server forever.
I tried using the command "forever start -c "npm start" ./" its not showing
To run npm start from pm2 you can run pm2 start npm -- start. This will run any command that is written within package.json start section.
Why don't you try to use PM2 (Node process manager: http://pm2.keymetrics.io/)?

How do I add a custom script to my package.json file that runs a javascript file?

I want to be able to execute the command script1 in a project directory that will run node script1.js.
script1.js is a file in the same directory. The command needs to be specific to the project directory, meaning that if I send someone else the project folder, they will be able to run the same command.
So far I've tried adding:
"scripts": {
"script1": "node script1.js"
}
to my package.json file but when I try running script1 I get the following output:
zsh: command not found: script1
Does anyone know the steps necessary to add the script mentioned above to the project folder?
*Note: the command can not be added to the bash profile (cannot be a machine specific command)
Please let me know if you need any clarification.
Custom Scripts
npm run-script <custom_script_name>
or
npm run <custom_script_name>
In your example, you would want to run npm run-script script1 or npm run script1.
See https://docs.npmjs.com/cli/run-script
Lifecycle Scripts
Node also allows you to run custom scripts for certain lifecycle events, like after npm install is run. These can be found here.
For example:
"scripts": {
"postinstall": "electron-rebuild",
},
This would run electron-rebuild after a npm install command.
I have created the following, and it's working on my system. Please try this:
package.json:
{
"name": "test app",
"version": "1.0.0",
"scripts": {
"start": "node script1.js"
}
}
script1.js:
console.log('testing')
From your command line run the following command:
npm start
Additional use case
My package.json file has generally the following scripts, which enable me to watch my files for typescript, sass compilations and running a server as well.
"scripts": {
"start": "concurrently \"sass --watch ./style/sass:./style/css\" \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
}
Steps are below:
In package.json add:
"bin":{
"script1": "bin/script1.js"
}
Create a bin folder in the project directory and add file runScript1.js with the code:
#! /usr/bin/env node
var shell = require("shelljs");
shell.exec("node step1script.js");
Run npm install shelljs in terminal
Run npm link in terminal
From terminal you can now run script1 which will run node script1.js
Reference: http://blog.npmjs.org/post/118810260230/building-a-simple-command-line-tool-with-npm
Lets say in scripts you want to run 2 commands with a single command:
"scripts":{
"start":"any command",
"singleCommandToRunTwoCommand":"some command here && npm start"
}
Now go to your terminal and run there npm run singleCommandToRunTwoCommand.
Suppose I have this line of scripts in my "package.json"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"export_advertisements": "node export.js advertisements",
"export_homedata": "node export.js homedata",
"export_customdata": "node export.js customdata",
"export_rooms": "node export.js rooms"
},
Now to run the script "export_advertisements", I will simply go to the terminal and type
npm run export_advertisements
Example:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"build_c": "ng build --prod && del \"../../server/front-end/*.*\" /s /q & xcopy /s dist \"../../server/front-end\"",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
As you can see, the script "build_c" is building the angular application, then deletes all old files from a directory, then finally copies the result build files.

Categories

Resources