npm install error code 128 - node.js

I am receiving the following error when trying to run npm install after a fresh install of Node and Git
Anyone have any idea what could be causing it, and what to do to fix it?
package.json (removed company details)
{
"name": "xxx",
"version": "1.0.0",
"description": "xxx",
"engines": {
"node": "5.0.0",
"npm": "3.3.9"
},
"repository": "xxx",
"private": true,
"license": "UNLICENSED",
"dependencies": {
"dijit": "https://github.com/dojo/dijit.git#1.10.4",
"dojo": "1.10.4",
"fg-dialog": "0.1.5",
"politespace": "0.1.4",
"shoestring": "1.0.3"
},
"devDependencies": {
"body-parser": "^1.14.1",
"chalk": "^1.1.1",
"compression": "^1.6.0",
"del": "^2.0.2",
"dojo-util": "https://github.com/dojo/util.git#1.10.4",
"express": "^4.13.3",
"glob": "^5.0.15",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-git": "^1.6.0",
"gulp-html-minifier": "^0.1.6",
"gulp-jsbeautifier": "^1.0.1",
"gulp-jshint": "^1.11.2",
"gulp-jshint-xml-file-reporter": "^0.5.1",
"gulp-jsonminify": "^1.0.0",
"gulp-replace": "^0.5.4",
"gulp-task-listing": "^1.0.1",
"gulp-uglify": "^1.4.1",
"gulp-util": "^3.0.6",
"gulp-zip": "^3.0.2",
"intern": "https://github.com/theintern/intern.git",
"jshint-stylish": "^2.0.1",
"merge-stream": "^1.0.0",
"minimist": "^1.2.0",
"open": "^0.0.5",
"q": "^1.4.1",
"request": "^2.65.0",
"require-dir": "^0.3.0",
"run-sequence": "^1.1.2",
"selenium-standalone": "^4.6.3"
},
"scripts": {
"postinstall": "gulp install"
}
}

A recommended first step is to use the latest npm:
npm install -g npm
(You may need sudo). You are using npm 2.x, the latest is 3.5.x.

In my case I had just upgraded npm and package-lock.json was trying to install one of the project's packages from an unavailable git commit version.
Deleting and letting npm re-create the file package-lock.json resolved the issue.
rm package-lock.json
Note: It looks like package-lock.json maintains more details about the node_modules tree, so in a complicated/version specific project it may be important to isolate the specific line(s) causing the issue, versus just delete the package-lock.json file.
https://docs.npmjs.com/files/package-lock.json

The error points at revisioning, specifically usage of 1.10.4. Check that the BitBucket repos for dijit.git and util.git are setup with tagging. More information on versioning/tagging at Atlassian: https://confluence.atlassian.com/bitbucket/use-repo-tags-321860179.html.
If you're using SSH with a saved password, the references to your personal repositories will need to connect via SSH using the format below.
git+ssh://git#bitbucket.org/{user}/{repository}.git

I had the same npm error code 128 but it also had a reference to the debug.log file in the npm-cache which revealed the real problem.
Two of the dependencies in the package.json were pointing to private repositories directly that I don't have access to.
Once I fixed that (details here) I was able to run npm install successfully. Note: no reinstall or update of npm required!

Firstly, I deleted the npm and npm-cache directories that locate in c:\myUser\AppData\Roaming.
Then, I excuted npm install -g npm. That resolved my problem.

I was also getting the same error on windows 10 and I fixed it by adding the ssh key again in the GitHub by generating using the following URL: https://help.github.com/enterprise/2.13/user/articles/connecting-to-github-with-ssh/
to check the Existing key use following commands:
Open Git Bash. press the windows button and search for Git Bash.
Enter ls -al ~/.ssh to see if existing SSH keys are present
Check the directory listing to see if you already have a public SSH key.
if key files exist it will list them(using default file name) like :
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub
After that, you have to make sure that ssh-agent is running
you can use eval $(ssh-agent -s) command to run the ssh-agent
After this, you have to add this existing key using the command: ssh-add ~/.ssh/id_rsa
now as you file is added you can get key to the clipboard using command clip < ~/.ssh/id_rsa.pub
go to GitHub site and click on settings in top right corner and add this ssh key to gitHub.
restart the command prompt and error will be fixed.
hope this will help someone.

you must use cmd as adminstrator in windows, or add sudo in linux

Remove the node_modules folder and delete package-lock.json file. Then run following commands,
npm cache clean --force
npm install

I used git Bash instead of cmd and it worked.

First Step
rm package-lock.json
rm -rf node_modules/
npm install -g npm
If above does not works, try changing the node version to previous versions.

For me the solution was as simple as executing this on the git bash:
export GIT_SSH_COMMAND='ssh'
My npm probably was using some other installed ssh program from somewhere on my pc and that one wasn't using the right credentials.

Saw this error while trying to install a package with quotation marks around the package name:
npm i 'foobar'
should be
npm i foobar

Related

Npm install being slow and lots of "cache miss" after nearly every library

While everything seems to work on my local computer;
Whenever I run nodejs inside a docker (docker run node:18) and I clone a project, type npm install to get all libraries and work with them, it is really slow. Like 10 seconds slow.
While it works quickly after this initial bump I also notice that each library (as far as I can tell) has a (cache miss) appended after the timing (which is around 10 seconds). What is happening is this a problem/can I fix it?
Just to stress: it happens in any docker, whether I use node-alpine, node docker or even just an ubuntu docker and install node there manually.
After some hints from #NaorTedgi I notice that this is indeed due to the fact that the package is situated outside the docker and linked through a volume. I also notice that the timing itself (the 15 seconds) is dependent on the amount of packages it tries to load. With a single package it's too fast too notice and with a few it's only half a second.
So to test it the following steps I take:
make a new directory (~/javascript-test) and put the following into a package.json file:
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "NODE_ENV=production node ./javascript/app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-redis": "^6.1.3",
"cookie-parser": "^1.4.6",
"date-fns": "^2.28.0",
"debug": "^4.3.3",
"express": "^4.17.2",
"express-session": "^1.17.2",
"http-errors": "^2.0.0",
"knex": "^2.1.0",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"nanoid": "^3.3.4",
"node-cron": "^3.0.1",
"objection": "^3.0.1",
"pg": "^8.7.1",
"redis": "^4.2.0",
"typescript": "^4.7.4",
"uuid": "^8.3.2"
}
}
Open shell to this directory and run (to initialize package.json)
npm install
rm -rf node_modules
Then run the docker with the volume (obviously with sudo if required):
docker run --name node-test --rm -it -v ~/javascript-test:/javascript node:18
Open a second shell (since the default entrypoint isn't sh from the node dockers) and execute:
docker exec -it node-test sh
Inside the docker shell:
cd javascript && npm install
With these steps I notice cache misses after 2 seconds.
Finally I notice that if I do remove node_modules and reinstall the modules (npm install) a second time inside the docker no cache misses happen. So to test a second time one has to end the node docker and rerun it (docker run... in first shell).
For those who like a dockerfile, this is the simplest file that still exhibit the error (once again make sure to bind the volume containing above `package.json` and the corresponding `package-lock.json`)
FROM node:18
WORKDIR /javascript
ENTRYPOINT npm install
A git repository of the Dockerfile and the package.json/package-lock.json files: https://github.com/pulli23/docker-npm-test
run it through (if cloned into ~/dockertest)
sudo docker build -t nodetest . && sudo docker run --name node-test --rm -it -v ~/dockertest/javascript-test:/javascript nodetest
My guess it is an issue related to networking (f.e. proxy) or authentication (f.e. connection to enterprise repository). Your local connection has something what your container is missing, maybe some certificate.
You should go into the container and test if you can reach the repository.
few things you need to check:
if your using more then one registry make sure npm is your default
npm config set registry=https://registry.npmjs.com/
if your project repository has package-lock.json
then make sure your not using volume to the current directory node_modules dir to your image if so it will be much faster to delete node_modules before installation
run install with ci => npm ci
make sure your package-lock.json is generated from the ‘npm i’ command from inside the container! Runing npm i locally will genreate libraries competable to your local node version and in case of c++ add ons genreate dll,so or dylib file according to your OS

Is is possible to install dependancies with single line command?

My Node.js
package.json
has following dependancies
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"mongoose": "^5.3.10",
"nodemon": "^1.18.5"
},
"devDependencies": {
"eslint": "^5.8.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0"
},
I am new to JS,so I want to know if we can somehow invoke package.json without going for
npm install
for every package.
When you use the command npm install or npm i, it will install all dependencies from your package.json.
As a result you get all the dependencies listed in the package.json from the current folder
You can see the documentation concerning this command here : npm install
Welcome to JS world, I'm fairly new to JS myself but I believe there two possible solutions to your problem:
npm install multiple dependencies
It is possible to install multiple dependencies at the same time with one npm install command, you may find more information that could be helpful in the documentation.
For example:
npm install got koa fs-extra
Here I have installed all 3 of my project dependencies at once.
Pre Populate package.json
You can manually add the package dependencies in the correct format to your package.json file. You might the npm documentation on the package.json file helpful.
You then will need to run:
npm install
This will take the dependencies in the package.json file and install them into the node_modules/ directory.

How do I identify which npm packages are just peer dependencies?

I'm trying to remove unused packages from the package.json files for a few projects but I'm running into issues with peer dependencies. There are some tools, such as depcheck, which try to list all of the "unused" packages, but it doesn't differentiate between actual unused packages, and packages that are unused because they're peer dependencies.
Is there a package out there, or some npm command I'm not familiar with, that will allow me to either list all peer dependencies in my project or, at the very least, allow me to type in a package name and see if that package is installed because it's a peer dependency of another package?
For posterity, here's an example of just the dependencies for one of my projects. In this project, I know for instance that reflect-metadata is a peer dependency of #nestjs/common, but I only discovered that after uninstalling it.
"dependencies": {
"#google-cloud/storage": "^3.2.1",
"#google-cloud/vision": "^1.3.0",
"#google/maps": "^0.5.5",
"#nestjs/common": "^6.6.7",
"#nestjs/core": "^6.6.7",
"#nestjs/platform-express": "^6.6.7",
"#slack/webhook": "^5.0.1",
"#typeform/api-client": "^1.5.1",
"algoliasearch": "^3.34.0",
"array-uniq": "^2.1.0",
"basic-auth": "^2.0.1",
"child-process-promise": "^2.2.1",
"class-transformer": "^0.2.3",
"class-validator": "^0.10.0",
"express": "^4.17.1",
"firebase-admin": "^8.5.0",
"firebase-functions": "^3.2.0",
"geoip-lite": "^1.3.8",
"geolib": "^3.0.4",
"glob": "^7.1.4",
"hbs": "^4.0.4",
"hubspot-api": "^2.2.10",
"json2csv": "^4.5.3",
"lodash": "^4.17.15",
"luxon": "^1.17.2",
"node-fetch": "^2.6.0",
"postmark": "^2.2.9",
"promise-settle": "^0.3.0",
"qrcode": "^1.4.1",
"redux": "^4.0.4",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.5.3",
"sales-tax": "^2.0.10",
"sanitize-filename": "^1.6.3",
"sharp": "^0.23.0",
"stripe": "^7.9.0"
},
This is a great question, not sure why it was downvoted.
Unfortunately I don't know of an existing, nicely automated way to do this.
You can test an individual package like so:
npm uninstall some-package && npm ls
If there are any peer dependency violations, they will be printed out and the command will exit nonzero.
So you could combine this with the output of one of the other tools mentioned, iterate through the candidates for orphaned packages, remove them one-by-one, and test the output between each change. Then do an npm uninstall --save to commit the ones that didn't produce an error, or npm install to roll back the ones that do. This could be automated, but I will leave that as an exercise to the reader.
check-peer-deps
Verifies that the peerDependency requirements of all top level dependencies are satisfied.
Installation
You can install this on your system with:
npm i -g check-peer-deps
Please note that this utility requires npm to be available.
Usage
Simply change into the directory of the project you wish to check the peerDependencies of and run the program.
 cd foobar
 check-peer-deps
If the minimum versions of all your top level peerDependencies are satisfied then there will be no output, otherwise you will see something similar to this:
check-peer-deps A dependency satisfying eslint-config-airbnb-base's peerDependency of 'eslint#^4.9.0' was not found! Current: eslint#^4.6.0 Package dependencies can satisfy the peerDependency? Yes
This tells you that eslint-config-airbnb-base is requiring eslint#^4.9.0 as a peerDependency, but the project currently only specifies eslint#^4.6.0, allowing a potential issue to arise if eslint#4.6.0 was installed and not updated before installing. The output also tells you that although the minimum allowed version is too low, the maximum allowed version does satisfy the peerDependencies requirement.
install-peers-cli
CLI to install project's peerDependencies, without side effects. Works with npm, yarn. Supports yarn workspaces flow.
Install
yarn
$ yarn add --dev install-peers-cli
npm
$ npm install --save-dev install-peers-cli
Usage
Add package.json script:
{
"scripts": {
"install-peers": "install-peers"
}
}
Then run yarn install-peers (or npm run install-peers) to install peer dependencies of your project. It won't update lock files or modify package.json, keeping your setup pure and clean. Any other lifecycle script could be used depending on your use case.
You still may see "unmet peer dependency" warnings during regular install phase, due to installation flow of npm/yarn.
There will be a file called package-lock.json after once you do npm install.
By analyzing package-lock.json file, you can understand the dependencies of each package.
For more details this blog can be referred.
Dependencies of a package are required for the correct running of the package.
But there are some optional dependencies, which can be skipped.
You can use --no-optional argument while installing so these extra packages will not be installed.
But make sure your application is working fine without these optional packages.

Angular 2 UNMET PEER Dependency Error on Windows 10

I am trying to run my web application on a Windows 10 Machine with the package.json (given below). I have Node version 5.6.0 and Npm version 3.6.0. But unfortunately it's always throwing an UNMET Peer Dependency Error and the following files of the AngularLoader Hierarchy fails to load when I run my project(powered by Laravel PHP): shim.js, zone.js, reflect.js, system.js. Contrary the same config runs absolutely smooth on a Linux Dev Machine. Any sort of help for installing the same on the Windows Machine will be highly appreciated as I am quite new to the Angular 2 Domain.
I have already tried the following:
rm -rf node_modules/
npm cache clean
npm install
And also installing like npm install angular/core angular/common angular-forms
P:S: Upgrading to Angular 4 is not an option. Sorry!!!
Here is my package.json:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"bootstrap-sass": "^3.3.7",
"gulp": "^3.9.1",
"jquery": "^3.1.0",
"laravel-elixir": "^6.0.0-11",
"laravel-elixir-vue-2": "^0.2.0",
"laravel-elixir-webpack-official": "^1.0.2",
"lodash": "^4.16.2",
"vue": "^2.0.1",
"vue-resource": "^1.0.3"
},
"dependencies": {
"#angular/common": "^2.1.2",
"#angular/core": "^2.1.2",
"#angular/forms": "^2.1.2",
"#ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.11",
"#types/jquery": "^2.0.41",
"jquery": "^3.2.1",
"ng2-ui": "^0.11.5",
"rxjs": "^5.0.0-beta.12",
"zone.js": "^0.6.26"
}
}
Here is the full install log of the Windows Machine:`
Link to Error Doc
If you use libraries that depend on Angular 4 you can expect these errors.
Take ng-bootstrap 1.0.0-alpha.25 for example; If you check the CHANGELOG.md file;
BREAKING CHANGES
ng-bootstrap requires a minimal version of Angular 4.0.3
So why does this happen? Short answer; you should get rid of the version tags ^and ~ as this is your problem to begin with:
"^1.0.0-alpha.11" allows for versions >= 1.0.0-alpha.11 < 2.0.0
use "#ng-bootstrap/ng-bootstrap": "1.0.0-alpha.11" instead.
I suggest you read up on npm semver
Some might say you do not have to drop it completely but I've had my fair share of issues. Not all developers understand semantic versioning it seems. Also, it's a very bad idea to use these wildcards with alpha and beta packages as they come with breaking changes by default it seems.
How to fix it from here?
You say you have a Linux Dev Machine where you can build this app without any issues. Try doing an npm shrinkwrap on that machine. This will write an npm-shrinkwrap.json file with all used library versions at that time. Then, when doing an npm install on the Windows 10 machine, this file will be checked to see what versions should be downloaded instead.

NPM not creating .bin directory

I'm using npm v1.4.4 and node v0.10.25 on Mac OS X 10.9.2.
I've recently upgraded node and npm, and now npm install is no longer creating the .bin directory in node_modules.
I've deleted node_modules, tried npm install again, but the directory and binaries are never created.
Does anybody have any ideas as to why this is happening?
Here is my package.json:
{
"name": "redacted",
"author": {},
"description": "redacted",
"dependencies": {
},
"devDependencies": {
"karma": "*",
"karma-coverage": "0.1.2",
"karma-junit-reporter": "*",
"karma-coffee-preprocessor": "~0.1",
"grunt": "^0.4.2",
"grunt-contrib-requirejs": "^0.4.3",
"grunt-contrib-concat": "^0.3.0",
"grunt-contrib-sass": "^0.7.2",
"grunt-contrib-htmlmin": "^0.2.0",
"grunt-contrib-cssmin": "^0.7.0",
"grunt-contrib-coffee": "^0.10.1",
"grunt-contrib-uglify": "^0.3.3",
"grunt-contrib-jst": "^0.5.1",
"grunt-contrib-qunit": "^0.4.0",
"grunt-contrib-jshint": "^0.8.0",
"grunt-contrib-watch": "^0.5.3",
"grunt-contrib-jasmine": "^0.6.1",
"grunt-contrib-compress": "^0.6.1",
"grunt-contrib-handlebars": "^0.6.1",
"grunt-contrib-less": "^0.9.0",
"grunt-contrib": "^0.9.0"
}
}
I know this is an old post but I experienced the same issue recently. I had copied files from an existing project including package.json and package-lock.json. The package-lock.json was what prevented the node_module/.bin directory from being created.
The solution was to delete the node_modules directory and package-lock.json and run npm install again
The ./node_modules/.bin directory is where npm creates links to a node package's binary. From https://docs.npmjs.com/files/folders#executables
Executables
When in global mode, executables are linked into
{prefix}/bin on Unix, or directly into {prefix} on Windows.
When in local mode, executables are linked into ./node_modules/.bin so
that they can be made available to scripts run through npm. (For
example, so that a test runner will be in the path when you run npm
test.)
The package.json you pasted above do not have a bin section. Take a look at this example from npm's package.json
{
"version": "1.4.9",
"name": "npm",
"publishConfig": {
"proprietary-attribs": false
},
"description": "A package manager for node",
...
...
"main": "./lib/npm.js",
"bin": "./bin/npm-cli.js",
"dependencies": {
"abbrev": "~1.0.4",
"ansi": "~0.2.1",
...
...
Specifically the line "bin": "./bin/npm-cli.js" will tell npm to create a link at ./node_modules/.bin/npm to node_modules/npm/npm-cli.js
Seems that all your dependencies are dev dependencies.
Could you see if your NODE_ENV environment variable is set to production now? If yes you will need to change it back.
Also, any error happened during installation?
If all packages installed, only the .bin is gone.
you can just run npm rebuild
In my case I had webpack running in watch mode in another console window. I did not get any errors during npm install so it took me a moment to notice.
Ensure the dependencies are not in use, such as karma running tests or webpack running in watch mode
Delete the dependency folders, such as node_modules/karma, or the entire node_modules folder. NPM does not seem to create symlink files in .bin folder if dependency folder already exists.
Retry npm install
With NPM 6.7.0.
Not really an answer to your question, but because I had a similar situation: I run npm with the --no-bin-links option on my VM so my windows host doesn't complain. And then later I don't find the bin links folder... duh!
This could happen because of the broken npm. Try following command from the npm troubleshooting and it should just work fine.
curl -L https://www.npmjs.org/install.sh | sh

Resources