Given a package.json that includes the following scripts:
"scripts": {
"dev": "npm install && webpack-dev-server --hot --progress --colors",
"build": "npm install && webpack --env.prod --progress --colors",
"start": "npm run dev"
}
Running npm start gives me many errors of the sort
`npm WARN tar ENOENT: no such file or directory, open 'C:\repos\my-project\node_modules\.staging\core-js-ea8988d1\client\shim.js'
followed by
npm ERR! code 1
npm ERR! Command failed: git submodule update -q --init --recursive
npm ERR! C:/Users/JohnDoe/AppData/Local/Programs/Git/mingw64/libexec/git-core\git-submodule: line 21: .: git-sh-setup: file not found
However, if instead I just run npm install directly, the npm installation of packages succeeds with no errors, and then I can run npm start thereafter with no issues. Why is this? There seems to be some kind of issue with including npm install in an npm script if the packages are not yet installed. I also tried setting start to "npm install" but running npm start gave me the same errors in that case.
I want to call multiple commands with the dev command. I found here that using concurrently is the best way to make this work since this would work on multiple OS.
How can I run multiple npm scripts in parallel?
I rand the folllwing aswell
npm install -g npm-windows-upgrade
npm install -g concurrently
npm install concurrently
I can run them individually. But when I run the script with npm run dev I get the following error. Why can't npm find those commands?
Terminal
[0] 'watch-client' is not recognized as an internal or external command,
[0] operable program or batch file.
[1] 'watch-server' is not recognized as an internal or external command,
[1] operable program or batch file.
[0] watch-client exited with code 1
--> Sending SIGTERM to other processes..
[1] watch-server exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! diepio#1.0.0 dev: `concurrently --kill-others "watch-client" "watch-server"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the diepio#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\31614\AppData\Roaming\npm-cache\_logs\2019-12-24T11_09_40_394Z-debug.log
Package.json
"scripts": {
"dev": "concurrently --kill-others \"watch-client\" \"watch-server\" \"serve\"",
"watch-client": "parcel ./src/client/index.html --open --out-dir ./builds/development/public",
"watch-server": "parcel ./src/server/index.ts --out-dir ./builds/development/private --target node",
"serve": "nodemon ./builds/development/private"
}
You may need to add npm and its submodules into your system PATH.
Have you downloaded the npm modules into your project directory?
You could also check that you have installed your npm submodules with the global argument.
The problem was that I was running the scripts in the wrong way I had to do it like this "dev": "concurrently --kill-others \"npm run watch-client\" \"npm run watch-server\" \"npm run serve\"",
I have installed node.js.
Next, I installed cnmp with command
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install
when I tried command cnpm run dev
there is a error:
npm ERR! path C:\Users\Harry\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Harry\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Harry\AppData\Roaming\npm-cache\_logs\2018-08-03T02_48_22_663Z-debug.log
so I moved the package.json from C:\Users\Harry\AppData\Roaming\npm\node_modules\cnpm to 'C:\Users\Harry\package.json'
but I still got an error:
npm ERR! missing script: dev
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Harry\AppData\Roaming\npm-cache\_logs\2018-08-03T02_51_46_194Z-debug.log
and I also tried methods of similar problems, such as edit the script in package.json, it still doesn't work.
Perhaps you are using the Vue CLI 3? If yes, there is no "dev" build script. Earlier versions of the Vue 2 boilerplate project had a "dev" script - but no longer.
Instead use the "serve" script and your Vue project will run as dev
npm run serve
See the scripts that are configured with Vue CLI 3 in the package.json file
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint" },
Hope that solves your issue.
Will a ReactJS app project be ended when I simply close the CLI, while in first instance the Node.js Package Manager was running the developer server through the "npm start"-command in the CLI? Or will the ReactJS app project run in the background?
If the second question is true, how can I otherwise stop the ReactJS app project without having to worry that I have to run "npm run eject" in the CLI and never being able to run the ReactJS app project in the development stage? The following occurs when I do so (run "npm run eject" in the CLI) for the second time:
npm ERR! path C:\Users\1st assembled M-PC\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\1st assembled M-PC\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\1st assembled M-PC\AppData\Roaming\npm-cache\_logs\2018-04-27T17_27_41_529Z-debug.log
If your app is running simply press Control + C to halt it. Closing the Command Prompt will achieve the same result. You will still be able to run it again with npm run start after this.
A note on ejecting – to successfully eject you need to run npm run eject from your project folder. However this operation is usually needed only if you are a power user and you aren't happy with the default configuration.
I'm using npm run script to do tasks such as "build" and "test".
For example, my package.json looks like the following:
{
"name": "fulfillment-service",
"version": "1.0.0",
"description": "Endpoint for CRUD operations on fulfillment status",
"main": "src/server.js",
"scripts": {
"build": "tsc",
"test": "tape tests/*.js"
},
"dependencies": {},
"devDependencies": {
"typescript": "^1.8.10"
}
}
When I run npm run build and it is successful, the output is the following:
> fulfillment-service#1.0.0 build d:\code\fulfillment-service
> tsc
When I run npm run build and it fails, the output is the following:
> fulfillment-service#1.0.0 build d:\code\fulfillment-service
> tsc
src/server.ts(51,81): error TS2339: Property 'connection' does not exist on type 'IncomingMessage'.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! fulfillment-service#1.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the fulfillment-service#1.0.0 build script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fulfillment-service package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs fulfillment-service
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls fulfillment-service
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! d:\code\fulfillment-service\npm-debug.log
This fills the entire console with useless information, and I have to scroll to the top to see why it failed.
Is there anyway to hide/silence the lines that start with npm ERR! during development?
You have to use npm run build --silent.
This isn't documented in npm help, npm help run, or anything else obvious, but with some searching on the internet you can find out that apparently it is documented in npm help 7 config. You can also use the loglevel option in .npmrc.
The --silent (short: -s) option suppresses:
The two lines beginning with > that say what command you're running.
npm ERR! errors.
Creating an npm-debug.log if there's an error.
Note: using npm scripts to run other npm scripts may require you to use --silent more than once. Example package.json:
{
. . .
"scripts": {
"compile": "tsc",
"minify": "uglifyjs --some --options",
"build": "npm run compile && npm run minify"
}
}
If you do npm run build and TypeScript finds an error, then you'll get the npm ERR! from both scripts. To suppress them, you have to change the build script to npm run compile --silent && npm run minify and run it with npm run build --silent.
Add file .npmrc to project and put in the file loglevel=silent.
A variation on other posts related to this (but not enough cred to comment!), and a little quicker/convenient as a stop gap is that you can change the exit status of processes that npm is running in situ, so that it doesn't think it failed. Obviously this will not stop chained commands from running after it. Sh does boolean evaluation similar to JS, just add || true on the end, e.g.:
"myscript": "eslint || true"
Hopefully this is also obvious enough that other devs can find it before they come looking for you!
There is an issue filed on npm: run-scripts are too noisy while used in development #8821 (also mentioned in a comment above)
In the discussion in that issue, a couple of people have mentioned creating an alias e.g. npr (utilizing the --silent option gcampbell describes in his/her answer). Although --silent can hide some npm type issues such as a malformed package.json, this seems like a reasonable solution for now.
alias npr='npm run --silent $*'
One other thing from that discussion which may be worth looking into, although it is yet another tool, is yarn which is described on a facebook blog post.
As others have noted, the problem with --silent is you lose all output. There's another way that seems to work for most cases:
npm run something 2>/dev/null
If one of the binaries you are running happens to write to stderr, then that will be suppressed. But most node stuff writes to stdout, so it shouldn't be a problem.
Of course this will work only in a shell environment that supports output redirection.
In case if you've created a custom script and it returns with the NPM error (even there's no error), add
process.exitCode = 0;
at the end of the script to avoid error.