Cannot run npm commands due to sh: 1: webpack: not found error; same exact codebase runs commands fine elsewhere - npm

I'm having a very strange issue with nvm, npm and webpack.
We have a webpack file with a npm run publish command. I have 4 stacks setup locally on the same code repository. In 3 of the stacks, I can npm run publish without an issue. However, in the 4th stack I always get a sh: 1: webpack: not found error when I run the command. The worrisome bit, is the codebases are identical. I've ran diffs, altered permissions, ran npm rebuild, re-ran npm install and nvm use. I've removed the node_modules directory and ran an npm install. No matter what I do, I get the same error.
Here is the verbose error with a few local names blocked out:
21 timing command:run-script Completed in 25ms
22 verbose stack Error: command failed
22 verbose stack at ChildProcess.proc.on (/home/<usr>/.nvm/versions/node/v11.14.0/lib/node_modules/npm/node_modules/#npmcli/promise-spawn/index.js:64:27)
22 verbose stack at ChildProcess.emit (events.js:193:13)
22 verbose stack at maybeClose (internal/child_process.js:999:16)
22 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5)
Any help is very much appreciated! Thanks!

I ended up resolving it by copying over the node_modules directory from one of the working codebases. Not entirely sure what the problem was though.

Related

npm install fails with 405 Method Not Allowed

I am currently working on upgrade some projects to use node 18 with npm 8, from node 12 with npm 6.
We're using github as npm repository for our private packages.
Now I am getting this error on npm install:
npm ERR! code E405
npm ERR! 405 Method Not Allowed - GET https://npm.pkg.github.com/<our-github-organisation>/#types/mime/-/mime-3.0.1.tgz
In the error log:
456 verbose stack HttpErrorGeneral: 405 Method Not Allowed - GET https://npm.pkg.github.com/<our-github-organisation>/#types/mime/-/mime-3.0.1.tgz
456 verbose stack at /home/cclausen/.nvm/versions/node/v18.7.0/lib/node_modules/npm/node_modules/npm-registry-fetch/lib/check-response.js:93:15
456 verbose stack at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
457 verbose statusCode 405
458 verbose pkgid #types/mime#https://npm.pkg.github.com/<our-github-organisation>/#types/mime/-/mime-3.0.1.tgz
This does not happen on every package, only on a few select ones, I can't see pattern.
None of the affected patterns our ours, just random packages.
Why would this happen?
It seems the content of the .npmrc file used in the repository to specifc from where to get packages has changed, updating that file to comply with the newest information from githubs documentation has fixed this issue.
So the new content for me is:
#OWNER:registry=https://npm.pkg.github.com
Where OWNER is my organisation.

"Already up-to-date" and "Run 'yarn' to install missing dependencies"?

I've got a bit of a weird situation where "ember s" reports "Missing yarn packages" followed by a list of missing packages (two of them) and then "Run 'yarn' to install missing dependencies".
However when I run 'yarn' I get the message "success Already up-to-date" .
Any ideas how to get out of this circle ?
There's something I did immediately before this started which I guess is the source of my problem
Getting rid of an Add-on
I had installed an Ember Add-on which had generated problems so I decided to get rid of it . To do that I did the following :
git push -f origin 913c2dee12b0363df0664c9c63e0443abe0adb57:foo-bar
git reset --hard 913c2dee12b0363df0664c9c63e0443abe0adb57
yarn
yarn install
yarn clean
yarn install
yarn
Where 913c2dee12b0363df0664c9c63e0443abe0adb57 was the last commit before the unwanted add-on was installed. I don't think there was anything wrong in doing that but now I'm wondering.
Output of running Ember Server
When I run 'ember s' I get this output ...
DEPRECATION: ember-cli-babel 5.x has been deprecated. Please upgrade to at least ember-cli-babel 6.6. Version 5.2.8 located: foobar -> ember-cli-build-date -> ember-cli-babel
Missing yarn packages:
Package: #bower_components/jquery
* Specified: jquery/jquery-dist#
* Installed: (not installed)
Package: #bower_components/jstree
* Specified: vakata/jstree#^3.3.5
* Installed: (not installed)
Run `yarn` to install missing dependencies.
Stack Trace and Error Report: /tmp/error.dump.33c6e8c0abc9fc8abd355dc080268f9c.log
An error occurred in the constructor for ember-cli-dependency-checker at /media/mint/dev/foobar/node_modules/ember-cli-dependency-checker
Warning about ember-cli versions
I don't think this is relevant but just for completeness
Running the 'yarn' results in the following appearing in the output text ...
warning foobar#0.0.0: "dependencies" has dependency "ember-cli" with range "~3.8.1" that collides with a dependency in "devDependencies" of the same name with version "3.8"
EDIT: OK I was able to resolve this with the help of the comment by dwenzel ...
rm -rf node_modules && yarn
Although that actually led into a different issue which I'm almost certain was unrelated but I'll just mention it here in case it's useful to those who come after.
The execution of yarn initially failed with the following error ...
35238 verbose stack Error: node-sass#4.5.3 postinstall: `node scripts/build.js`
35238 verbose stack Exit status 1
35238 verbose stack at EventEmitter.<anonymous> (/home/rshea/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
35238 verbose stack at EventEmitter.emit (events.js:189:13)
35238 verbose stack at ChildProcess.<anonymous> (/home/rshea/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
35238 verbose stack at ChildProcess.emit (events.js:189:13)
35238 verbose stack at maybeClose (internal/child_process.js:970:16)
35238 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
35239 verbose pkgid node-sass#4.5.3
35240 verbose cwd /media/mintextra/dev/ddn-build-test-temp/foobar
35241 verbose Linux 3.13.0-169-generic
35242 verbose argv "/home/rshea/.nvm/versions/node/v10.15.3/bin/node" "/home/rshea/.nvm/versions/node/v10.15.3/bin/npm" "install"
35243 verbose node v10.15.3
35244 verbose npm v6.4.1
35245 error code ELIFECYCLE
35246 error errno 1
35247 error node-sass#4.5.3 postinstall: `node scripts/build.js`
35247 error Exit status 1
35248 error Failed at the node-sass#4.5.3 postinstall script.
35248 error This is probably not a problem with npm. There is likely additional logging output above.
35249 verbose exit [ 1, true ]
I was able to resolve that with ...
npm install node-sass#latest
npm install
... at which point ember s was able to run without errors.
It looks like you want to do yarn install --check-files to verify that the files have not been removed from node_modules. This avoids having to wipe out your node_modules file which can be time consuming.
https://classic.yarnpkg.com/en/docs/cli/install/#toc-yarn-install-check-files
https://github.com/yarnpkg/yarn/issues/2240
When yarn gets confused like this, you can usually fix things up by clearing out your node modules before installing:
rm -rf node_modules && yarn
The way I managed to get around this without deleting the entire node_modules directory was just to remove the module from topLevelPatterns within node_modules/.yarn-integrity.
Disclaimer: I don't know what the implications of this are but yarn's integrity was already questionable and it works so meh!?
You may also try to reinstall/download all packages with:
yarn install --force

Unable to install NPM packages due to path length constraint using NPM 5.X

I'm running Windows 10, NPM v5.5.1, and node v8.9.1.
Edit: I have since updated to node v8.9.4 and npm v5.6.0. The problem remains unchanged.
I set up my development environment on this machine about 2 months ago. I'm using Angular CLI to build my client apps.
Everything was going fine. I added a few packages via NPM without a problem, such as Gulp and ngx-bootstrap. Then I started to run into errors on some of my package installs.
The errors are:
npm ERR! code PATH_LENGTH_EXCEEDED
npm ERR! errno PATH_LENGTH_EXCEEDED
npm ERR! request to https://registry/npmjs.org/{{package}} failed, reason: path length constraint exceeded
npm ERR! A complete log of this run can be found in:
npm ERR! {{npm_cache path}}\_logs\2018-02-08T14_43_40_856Z-debug.log
The contents of that log file are:
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 'install',
1 verbose cli 'ngx-cookie-service',
1 verbose cli '--save' ]
2 info using npm#5.5.1
3 info using node#v8.9.1
4 verbose npm-session d55be12849534a0a
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData error for ngx-cookie-service#latest request to https://registry.npmjs.org/ngx-cookie-service failed, reason: path length constraint exceeded
8 verbose type system
9 verbose stack FetchError: request to https://registry.npmjs.org/ngx-cookie-service failed, reason: path length constraint exceeded
9 verbose stack at ClientRequest.req.on.err (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\src\index.js:68:14)
9 verbose stack at emitOne (events.js:116:13)
9 verbose stack at ClientRequest.emit (events.js:211:7)
9 verbose stack at TLSSocket.socketErrorListener (_http_client.js:387:9)
9 verbose stack at emitOne (events.js:116:13)
9 verbose stack at TLSSocket.emit (events.js:211:7)
9 verbose stack at emitErrorNT (internal/streams/destroy.js:64:8)
9 verbose stack at _combinedTickCallback (internal/process/next_tick.js:138:11)
9 verbose stack at process._tickCallback (internal/process/next_tick.js:180:9)
10 verbose cwd C:\Development\test
11 verbose Windows_NT 10.0.15063
12 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "ngx-cookie-service" "--save"
13 verbose node v8.9.1
14 verbose npm v5.5.1
15 error code PATH_LENGTH_EXCEEDED
16 error errno PATH_LENGTH_EXCEEDED
17 error request to https://registry.npmjs.org/ngx-cookie-service failed, reason: path length constraint exceeded
18 verbose exit [ 1, true ]
I researched this, and found the Windows 10 file path 260 character limitation. I thought that npm version 3.1.0 should have fixed this issue, but I decided to followed the instructions in this answer, because I'm still running into this issue despite using NPM v5.5.1.
I found that my version of Windows was prior to the roll out of the feature that lets you disable this limitation. I updated to Version 1703 (OS Build 15063.483), and to enable Win32 long paths.
Yet I'm still getting the error, and unable to install a variety of npm packages.
In testing to see if it was an issue with packages that have a lot of dependencies, I tried installing or reinstalling a couple of other packages.
Some fail with the errors above. Others succeed with the following warnings:
npm WARN Unexepcted warming for https://registry.npmjs.org/: Miscellaneous Warning PATH_LENGTH_EXCEEDED: request to https://registry.npmjs.org/{{package name}} failed, reason: path length constraint exceeded
npm WARN Using stale package data from https://registry.npmjs.org/ due to a request error during validation
Packages throwing the error include:
jslint
ngx-cookie-service
chart.js
angular-cli
Packages that throw the warnings include:
font-awesome
#angular/cli
moment
ngx-bootstrap
bootstrap
jasmine
I suspect that something has changed, either in a policy on my workstation, or in our network security, that is causing this. All of the packages that succeed seem to be packages that I had previously installed, either as a direct install, or as a dependency of #angular/cli (one of the first packages I installed). I'm assuming that the stale package data warning indicates that whatever problem I have with the path length is preventing updated data being retrieved, and therefore npm is falling back to cached data from previous installations of the selected package and its dependencies.
So now I'm stumped as to how to diagnose exactly where the issue is happening. If its a security policy that changed, then I need to be able to describe exactly what is being blocked so that I can work with our security department to fix this. But the only information I can find about the PATH_LENGTH_EXCEEDED errors lead me to old information about versions of npm prior to 3.1.0.
How can I identify the source of this problem?
After additional searching, I found references to path length exceeded with regards to SSL/TLS certificate authorities. I tested this issue by changing the npm registry to use http instead of https (note: this is a temporary step only; I have turned https back on once I verified the issue):
npm config set registry http://registry.npmjs.org/
This allowed me to install the problematic packages.
It seems the underlying cause is SSL Inspection performed by our network security team. The decryption, inspection, and re-encryption process, and subsequent changes in the Issuing Authority on the certificate, apparently triggers this error.

npm install fails: buble#github:pemrouz/buble reference is not a tree

Summary:
I am looking for a strategy on how I might find and fix an error in package-lock.json. This error breaks npm install:
How do I figure out what installed this buble dependency?
Can I simply delete the entry?
How do I figure out what the reference value should be?
Details
I wanted to update my node_modules. So I deleted my node_modules directory, and ran npm install. While this has always worked in the past, it is now failing with the following error (found in the AppData\Roaming\npm-cache_logs\XXXX-debug.log):
13 silly fetchPackageMetaData error for buble#github:pemrouz/buble#fdcd2bac2c8945816b6fe3b032e49b58cc728b14 Command failed: C:\Program Files\Git\mingw64\bin\git.EXE checkout fdcd2bac2c8945816b6fe3b032e49b58cc728b14
13 silly fetchPackageMetaData fatal: reference is not a tree: fdcd2bac2c8945816b6fe3b032e49b58cc728b14
14 verbose stack Error: Command failed: C:\Program Files\Git\mingw64\bin\git.EXE checkout fdcd2bac2c8945816b6fe3b032e49b58cc728b14
14 verbose stack fatal: reference is not a tree: fdcd2bac2c8945816b6fe3b032e49b58cc728b14
14 verbose stack
14 verbose stack at ChildProcess.exithandler (child_process.js:271:12)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at ChildProcess.emit (events.js:213:7)
14 verbose stack at maybeClose (internal/child_process.js:927:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
I believe the reference is from /package-lock.json where I find 2 entries using this reference. Searching the Net has taught me that /package-lock.json is updated by npm. I do not know how this bubble package got added to my project - must be a dependency of some other package, but I lack the skills to figure out which. The entries look like the following:
...
"buble": {
"version": "github:pemrouz/buble#fdcd2bac2c8945816b6fe3b032e49b58cc728b14",
"requires": {
"acorn": "5.2.1",
...
Searching the Net for similar issues seem to be from users who are trying to sync up their repositories. Those solutions suggest ways to sync forks in Gitub which does not apply to my case. Near as I can tell, someone has updated the Github repository in some way which breaks this reference.
So, I am looking for a strategy on how I might fix this. How do I figure out what installed this buble dependency? Can I simply delete the entry? How do I figure out what the reference value should be?
Thanks in advance for any direction
I got this working. What I did was delete all references to buble in my package-lock.json file (after having made a back-up copy of course). I then deleted my node_modules directory, did npm cache clear --force, then npm install. npm was able to reload everything, and seems to have re-added the buble package to my package-lock.json now with a new reference value.
I do not know if all these steps were necessary; in the end I was getting desperate and ready to try everything. Hope this helps someone else!
I believe you can run npm install --no-optional buble which should prevent optional dependencies from being installed. Before you do this you should delete the old node_modules and start fresh.
https://docs.npmjs.com/cli/install
My problem was that I did not GIT github installed on my machine. You need to install Git, so the npm install can use it to download packages
I have similar problem but not quite same. I had this issue when I try to npm install inside my company network environment. Some certain SSH and HTTPS is blocked. The error message is
npm sill pacote Retrying git command: ls-remote -h -t https://github.com/pemrouz/buble.git attempt # 6
npm sill pacote Retrying git command: ls-remote -h -t https://github.com/pemrouz/buble.git attempt # 7
I removed package-lock.json and do npm install again. Everything was fine.
delete package-lock.json and do npm install again

npm install error - cb() never called

I try to install node_module in my angular project what I downloaded, but I get this error:
npm ERR! registry error parsing json
Then i reinstall npm using npm intall npm -g and after when i try use npm install I get this error:
(node:11252) UnhandledPromiseRejectionWarning: Unhandled promise
rejection (rejection id: 1): Error: ENOENT: no such file or directory, stat
'C:\Users\User\AppData\Roaming\npm-cache\_cacache\tmp\git-clone-ec5da46c\angular\cdk.es5.js'
debug.log:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install' ]
2 info using npm#5.4.2
3 info using node#v6.10.2
4 verbose npm-session ff5ce249dfe37f0e
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall spa#0.0.0
7 info lifecycle spa#0.0.0~preinstall: spa#0.0.0
8 silly install loadCurrentTree
9 silly install readLocalPackageData
10 silly install loadIdealTree
11 silly install cloneCurrentTreeToIdealTree
12 silly install loadShrinkwrap
13 info lifecycle #angular/cdk#2.0.0-beta.10-a7ce31e~prepack: #angular/cdk#2.0.0-beta.10-a7ce31e
14 error cb() never called!
15 error This is an error with npm itself. Please report this error at:
16 error <https://github.com/npm/npm/issues>
I already tried npm cache clean --force but i get same error.
node -v v6.10.2
npm -v 5.4.2
I had the same issue. I resolved it
by excluding package-lock.json file
npm i --no-package-lock
OR by manually deleting package-lock.json
Run npm cache clean --force and perform an install.
I had the same issue. I resolved it by remove nodejs#10 and install nodejs#8
On Windows 10 running npm install gave me this error.
I solved this issue by doing so from within Administrator: Command Prompt.
Ensure that you have a package.json file within the root of your angular project which should look something similar to this.
https://github.com/heroku/node-js-sample/blob/master/package.json
If the package.json file exists, you run npm install to get the packages saved to it and that will generate a node_modules directory for you.
However, if the file does not exist, it means you have to initialize npm into the project by running npm i -y which should automatically create a package.json file for you and as well allow you to install node modules.
NB: You have npm installed on your machine already so running npm install npm -g is not ideal.
I got this error when my package.json referred to a package using file:../(local path) and the directory didn't exist. Pointing it to the correct path resolved the error.
In my case... none of the above worked. I then deleted my package-lock.json. When I ran an npm install I got an error that a certain package could not be found in the repository. When I removed that from package.json my npm install worked!
I had the same issue. In my case it was caused by a syntax error within the .npmrc file, which was manually edited
Method 1:
npm cache clean --force then install your package
Method 2:
Disable your antivirus software and try to install your package
Method 3:
It is your internet connection, if you are using Wifi or an Ethernet connection use your cellular network or a different network and try to install your package