npm run build doesn't work with PowerShell ISE - node.js

I have a NodeJS project in Windows environment and I'm using Visual Studio and Power Shell ISE. In my package.json I have the following scripts:
"scripts": {
"start": "node ./bin/www",
"build": "del-cli public/js/app && webpack --config webpack.config.dev.js --progress --profile --watch",
"build:prod": "del-cli public/js/app && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail && del-cli 'public/js/app/**/*.js' 'public/js/app/**/*.js.map' '!public/js/app/bundle.js' '!public/js/app/*.chunk.js' 'assets/app/**/*.ngfactory.ts' 'assets/app/**/*.shim.ts'"
}
In the Power Shell, if I do "npm build" and then npm start, all go well and I update my server code running. But like this I need to restart all the process every time that I make a change. I saw a video that I could do "npm run build" and the process would keep running.
But when I do "npm run build" it all go well but the following:
...
building modules 541/542 modules 1 active
...er\src\animation\styles_collection.js
70% building modules 542/542 modules 0 active
12151ms building modules
At line:1 char:1
+ npm run build
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ( ...uilding modules:String) [],
RemoteException
+ FullyQualifiedErrorId : NativeCommandError
71% sealing
...
Then it continues until the end without any more exceptions but I think this error is not allowing the building to keep running because I still need to stop the npm process and restart it. Any one who can help me on this? Thanks in advance.

The error only happen in the PowerShell, in the normal cmd it doesn't happen but I still needed to do "npm start" each time I changed the server side code. I solved that by installing and using the nodemon plugin :) .

Related

how to run the preact application using webpack-dev-server

Please teach me the solution how to run the preact application using webpack-dev-server.
I am getting the following errors in "npm run start"
package.json file
npm run start
I fixed my error by changing "start:root" and "start:query" as follows.
"start:root": "SET NODE_ENV=development && webpack -p --config webpack.config.root.js --watch",
"start:query": "SET NODE_ENV=development && webpack -p --config webpack.config.query.js --watch",

Push rejected, failed to compile Node.js app while deploying in heroku

i am deploying my django+react app on heroku but its raising this error every time
Push rejected, failed to compile Node.js app
i have tried every thing remove cache delete package-lock.json update the node version according to .env file and other packages , app working fine in local but not deploying on server.i have this error so far at every time please help me to resolve i have also follow the heroku documentation to resolve this issue but not worked for me.
i have resolved my issue by little bit changing into my package.json file
before:
scripts": {
"start": "cd frontenduser && npm install && webpack-dev-server --env.NODE_ENV development",
"build": "cd frontenduser && npm install && webpack --env.NODE_ENV production",
"test": "jest --watch" },
after:
scripts": {
"start": "cd frontenduser && npm install ",
"build": "cd frontenduser && npm install",
"test": "jest --watch" },

node js build problem with an error "'.' is not recognized"

I am learning Node and working on a existing project which has build script as below:
"build": "npm run clean && ./node_modules/.bin/webpack --env=production --progress --profile --colors --display-optimization-bailout"
I did the npm install as per the instruction, but the build command gives an error below:
$ npm run build
> npm run clean && ./node_modules/.bin/webpack --env=development --progress --profile --colors --display-optimization-bailout
> rimraf build
'.' is not recognized as an internal or external command,
operable program or batch file.
Any idea on what I could be missing and how I can troubleshoot the problem, I am on windows pc. Thanks!
Wrap the path to webpack in JSON escaped double quotes, i.e. \"...\".
For instance:
"build": "npm run clean && \"./node_modules/.bin/webpack\" --env=production --progress --profile --colors --display-optimization-bailout"
^^ ^^

Increase node memory using npm package.json script

If you want to increase the memory limit in node, the option to be passed will be:
node --max-old-space-size=4096 yourFile.js
But in my scenario I am using yarn, my package.json looks like this:
{
"name": "myapp",
"productName": "myapp",
"version": "1.0.0",
"main": "app/main.js",
...
"scripts": {
"package-win": "npm run build && build --win --x64",
"package-mac": "npm run build && build --mac",
...
},
...
I execute yarn package-win on a windows machine to invoke electron-builder for my electron app built with react.js. But I get always npm ERR! code ELIFECYCLE Due to out of memory. In my mac also got the FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory Error but still got the packages generated (how? I don't know) when invoking yarn package-mac.
I search a lot on how to use the --max-old-space-size=4096 option, but I haven't found anything that works.
I tried "package-win": "node --max-old-space-size=4096 npm run build && build --win --x64", But the path have problems locating npm. Even if I use which npm, still which is not recognized.
Thanks for helping.
Answering to myself: Using this options in package-win is wrong. As package-win executes the build task, then:
"build": "npm run build-main && npm run build-renderer",
...
"build-main": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors",
That way it works!
You don't have to use option in package-win.
The way you should use-
"build-ts-prod": "node --max-old-space-size=1024
./node_modules/typescript/bin/tsc --skipLibCheck --diagnostics",

Npm scripts doesn't work the way I want

see below:
scripts": {
"build": "node_modules/.bin/babel sercer/src --out-dir server/dist ",
"build:watch": "node_modules/.bin/babel server/src --out-dir server/dist --watch",
"start:server": "node ./node_modules/nodemon/bin/nodemon.js ./server/dist/app.js",
"dev" : "(npm run build:watch) && (npm run start:server)"
}
you know, both of them can work well when I run npm run xxx , but when i conbian them like npm run dev does,the last one will not taking effect.what wrong with my script?
You could try
"dev" : "npm run build:watch && npm run start:server"
you can use the post- and pre- scripts that will be called before and after that script.
eg :
"build": "npm run build:css && npm run build:js",
"prebuild:js": "npm run lint"
In the above example build will execute both build:css and build:js - but not before running the lint task.

Resources