Why can't npm find my commands when using concurrently - npm

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\"",

Related

npm install command not working in npm script

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.

npm run script "command not found"

I try to build a project on macOS but the build fails.
I have in my package.json:
"scripts": {
...
"build": "build",
...
when I run npm run build I get the following error:
sh: build: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! project build: `build`
npm ERR! spawn ENOENT
There is file in the same folder that that is called "build", when I go there and execute the commands manually everything works fine. What could be the cause?
Given that you have set the execute permissions for the build script, you should be able to run it if you set up the build command like this:
"build": "./build"
I execute a php-based shell script to copy a reactjs file into a blade template (for Laravel) this way:
1 - inside my package.json
"production": "npx webpack --mode production && npm run rjs",
"rjs": "php sh_rjsToView.php",
2 - my php script I want to run directly after building my react-compiled stuff is located in the root of my project directory:
sh_rjsToView.php
3 - I'm not sure if it is absolutely necessary in this context, but remember to give execute permissions to the php script just above, so do this before you run it from package.json the first time:
chmod ug+x sh_rjsToView.php
4 - now run the whole thing:
npm run production

In Vue-CLI run dev, fail.

In the vue-cli, I want to npm run dev, but get the bellow error:
$ npm run dev
> vuejs-playlist#1.0.0 dev /Users/den/Desktop/Test/vue/vuejs-playlist
> cross-env NODE_ENV=development webpack-dev-server --open --hot
sh: cross-env: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! vuejs-playlist#1.0.0 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the vuejs-playlist#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/den/.npm/_logs/2018-02-02T11_54_11_067Z-debug.log
Try as follows for #vue/cli
npm run serve
In your traceback:
Local package.json exists, but node_modules missing, did you mean to install?
You should in your project root directory install the dependencies:
npm install
Or use its logogram npm i
As both answers before stated your build failed due needing to first:
npm install
Once that is complete, check your package.json file.
In there will have the default options for npm run followed by your build script option.
Example:
{
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
}
}
Resulting in your npm run serve is the same as vue-cli-service serve
Reference: Vue Docs

Can I hide or silence "npm ERR!" output when using npm run script?

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.

Unable to start app with npm start

I have followed the instructions in https://angular.io/guide/quickstart and created the corresponding quickstart files and installed dependencies using npm install command. After that when I issue npm start command I am getting the following error.
npm ERR! Linux 3.13.0-32-generic
npm ERR! argv "node" "/usr/local/bin/npm" "start"
npm ERR! node v0.10.25
npm ERR! npm v3.9.0
npm ERR! code ELIFECYCLE
npm ERR! angular2-quickstart#1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular2-quickstart#1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
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 angular2-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc && concurrently "npm run tsc:w" "npm run lite"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-quickstart
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/sobin/AngularTuts/heroappbase/npm-debug.log
First, I tried just running this command in the command prompt:
concurrently "npm run tsc:w" "npm run lite"
That worked. Then, in the package.json file, I replaced this line:
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
With this:
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
At that point, npm start worked normally. Hope that helps.
According to their docs, angular2 requires at least node 5.x.x
From their site:
Verify that you are running at least node v5.x.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors.
Looks like you are running node v0.10.25. Try upgrading.
To upgrade, you can use nvm which lets you switch easily between the versions. nvm on GitHub.