Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The command "npm run build -- --prod" exited with code 1 error

I'm developing an Asp.Net Core 2 and Angular 5 project in visual studio 2017.

When I'm going to publish my project then the error 'The command "npm run build -- --prod" exited with code 1' show in error list window.
I created the project with Angular CLI in ASP.NET Core 2 Angular template link and everything was fine and the project run and publish correctly.
After a while, I don't know what exactly happens that cause the project doesn't publish.

In the npm-debug.log file

0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 1 verbose cli   'run', 1 verbose cli   'build', 1 verbose cli   '--', 1 verbose cli   '--prod' ] 2 info using [email protected] 3 info using [email protected] 4 verbose stack Error: ENOENT: no such file or directory, open 'C:\Project\JWS\JWSApplication\package.json' 4 verbose stack     at Error (native) 5 verbose cwd C:\Project\JWS\JWSApplication 6 error Windows_NT 10.0.15063 7 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" "--" "--prod" 8 error node v6.10.3 9 error npm  v3.10.10 10 error path C:\Project\JWS\JWSApplication\package.json 11 error code ENOENT 12 error errno -4058 13 error syscall open 14 error enoent ENOENT: no such file or directory, open 'C:\Project\JWS\JWSApplication\package.json' 15 error enoent ENOENT: no such file or directory, open 'C:\Project\JWS\JWSApplication\package.json' 15 error enoent This is most likely not a problem with npm itself 15 error enoent and is related to npm not being able to find a file. 16 verbose exit [ -4058, true ] 
like image 938
Iman Bahrampour Avatar asked Apr 04 '18 05:04

Iman Bahrampour


People also ask

What does npm run build prod?

npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index. html , and requests to static paths like /static/js/main.

What is npm Run command?

npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.

What is npm build?

npm build is an internal command and is called by link and install commands, according to the documentation for build: This is the plumbing command called by npm link and npm install. You will not be calling npm build normally as it is used internally to build native C/C++ Node addons using node-gyp.


2 Answers

Perform any of the following options as long as there is an error

  1. For passing an argument to build command:

    change 'npm run build -- --prod' to 'npm run build --prod' in the .csproj file

  2. Open ClientApp folder and Update project angular-cli with this CMD command:

    npm install --save-dev @angular/cli@latest

  3. Update visual studio NodeJS and npm from:

    Tools > Options > Projects and Solutions > Web Package Management > External Web Tools

If NodeJS and npm aren't installed on your environment path Add NodeJS and npm folder to the top of the list else move $(path) to the top of the list

enter image description here.

Thank @Praveen Kumar and @Yerkon

like image 94
Iman Bahrampour Avatar answered Oct 01 '22 02:10

Iman Bahrampour


Got same error, my environment:

.NET Core 2.1 RC-1 Angular v5.2.4 NPM v5.7.1 Node v8.11.2 

And nothing mentioned above did not helped. Simple go to ".\ClientApp" //Angula-CLI project and run

npm run build 

then you will see real errors - so that means simple you have some errors in code, so fix angular UI code and it will build fine :).

like image 42
Drasius Avatar answered Oct 01 '22 04:10

Drasius