npm install command not working in npm script - npm

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.

Related

Why can't npm find my commands when using concurrently

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

Package.json missing script: stg

Using codeship to deploy to aws. Got error like
npm ERR! missing script: stg
custom script
git clone https://${GITHUB_KEY}#github.com/me/myproject.git
ls
cd myproject
composer install --no-interaction --prefer-dist
nvm install 6.9.4
npm install sync-exec
npm install
npm rebuild node-sass
npm run stg
partial webpack
"scripts": {
"clean": "rimraf public/dist",
"watch": "webpack --config webpack.dev.config.js --watch --progress",
"dev": "webpack --config webpack.dev.config.js --progress",
"prod": "cross-env npm run clean && NODE_ENV=production webpack --config webpack.config.js --progress --profile --colors",
"stg": "cross-env npm run clean && NODE_ENV=stage webpack --config webpack.dev.config.js --progress --profile --colors",
"lint": "eslint ./app/**/**.js"
},
codeship error
npm run stgnpm ERR! Linux 4.15.0-1009-aws
npm ERR! argv "/home/rof/.nvm/versions/node/v6.9.4/bin/node" "/home/rof/.nvm/versions/node/v6.9.4/bin/npm" "run" "stg"
npm ERR! node v6.9.4
npm ERR! npm v3.10.10
npm ERR! missing script: stg
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /home/rof/src/github.com/myaccountname/myproject/myproject/npm-debug.log

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

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.

Difficulty solving "sh: <npm package name> command not found" with npm run <npm package name>

I've been adding npm modules to my project for the first time (jshint, optimg, jpgo). I notice that some projects, when I do npm run [name], give a result of "sh: [name]: command not found."
I can't figure out why those don't work, but the other npm installs do. All these are installed locally; I can see the install by looking in the /node_modules folder in my project root and verify them with npm ls.
The latest package that gets this error is html-minify. My package.json looks like this (and validates at http://jsonlint.com/):
{
"name": "npmTest",
"devDependencies": {
"jshint": "latest",
"optimg": "latest",
"jpgo": "latest",
"ycssmin": "latest",
"html-minify": "latest"
},
"scripts": {
"lint": "jshint **.js",
"png": "optimg",
"jpg": "jpgo",
"css": "ycssmin **.css",
"html": "html-minify"
}
}
I tried "html-minify **.html" with the same resulting "not found" error.
Why would I get "sh: [npm package name]: command not found"? I've read the other threads, and because the other modules work, I doubt that I need to add anything to my PATH, or start a server, or install globally.
Fuller error message (for html5-lint):
$ npm run html
> npmTest# html /Users/Steve/Documents/APPS/Test_Apps/npmTest
> html5-lint
sh: html5-lint: command not found
npm ERR! npmTest# html: `html5-lint`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the npmTest# html script.
npm ERR! This is most likely a problem with the npmTest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! html5-lint
npm ERR! You can get their info via:
npm ERR! npm owner ls npmTest
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.1.0
npm ERR! command "node" "/usr/local/bin/npm" "run" "html"
npm ERR! cwd /Users/Steve/Documents/APPS/Test_Apps/npmTest
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Steve/Documents/APPS/Test_Apps/npmTest/npm-debug.log
npm ERR! not ok code 0
so short answer to run npm package commands locally
npm i install cowsay -d
then use
npx cowsay I am working locally
output should be
______
< I am working locally >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
on the other hand installing npm packages globaly on linux has problems with addministrator and node-module location
so best practice to get global packges to work normally is to install NVM first
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
then once nvm is installed install from nvm node
nvm install node
or a specific version
nvm install 12.18.3
now installing global packages and running them is simple
npm install -g cowsay
cowsay I am working globaly
will output
______
< I am working >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
now global packages are working fine and local packages can be run from the directory of the project using npx.
For the command not found issue you're seeing with html-minifier it could have to do with not globally installing the npm package (with a -g) or calling the command by the wrong name (I believe you're calling the package name html-minify when the package is defined as html-minifier)
Would suggest installing the command with a -g:
npm install html-minifier -g
and then running the html-minifier command:
html-minifier --help (to test installation)
html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true
Also for the scripts issue you're observing (where running npm run html is returning command not found)- here is a sample package.json. I ran npm run html (after globally installing html-minifier using the step above) and that runs html-minifier --help:
{
"name": "stackoverflow",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"html": "html-minifier --help"
},
"author": "",
"license": "ISC",
"dependencies": {
"html-minifier": "^4.0.0"
}
}
Github link: https://github.com/kangax/html-minifier
Npm link: https://www.npmjs.com/package/html-minifier
Installation and usage steps provided in the README:
Installation Instructions
From NPM for use as a command line app:
npm install html-minifier -g
From NPM for programmatic use:
npm install html-minifier
From Git:
git clone git://github.com/kangax/html-minifier.git
cd html-minifier
npm link .
Usage
Note that almost all options are disabled by default. For command line usage please see html-minifier --help for a list of available options. Experiment and find what works best for you and your project.
Sample command line: html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true
Node.js
var minify = require('html-minifier').minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
removeAttributeQuotes: true
});
result; // '<p title=blah id=moo>foo</p>'