33

I'm trying to install package.json file using the command npm install, but I'm getting the following error.

npm ERR! git dep preparation failed
npm ERR! command C:\Program Files\nodejs\node.exe C:\Users\DHRUV\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js install --force --cache=C:\Users\DHRUV\AppData\Local\npm-cache --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 128
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command git ls-remote ssh://git@github.com/gulpjs/gulp.git
npm ERR! npm ERR! Host key verification failed.
npm ERR! npm ERR! fatal: Could not read from remote repository.
npm ERR! npm ERR!
npm ERR! npm ERR! Please make sure you have the correct access rights
npm ERR! npm ERR! and the repository exists.
npm ERR!

I have installed Git and node.

package.json:

{
  "name": "LandTransfer",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test --watch=false",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "node patch.js"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "7.1.0",
    "@angular/cdk": "^7.1.0",
    "@angular/common": "7.1.0",
    "@angular/compiler": "7.1.0",
    "@angular/core": "7.1.0",
    "@angular/forms": "7.1.0",
    "@angular/http": "7.1.0",
    "@angular/material": "^7.1.0",
    "@angular/platform-browser": "7.1.0",
    "@angular/platform-browser-dynamic": "7.1.0",
    "@angular/platform-server": "7.1.0",
    "@angular/router": "7.1.0",
    "bootstrap": "^4.3.1",
    "core-js": "^2.5.7",
    "ethers": "^4.0.20",
    "rxjs": "^6.3.3",
    "truffle-contract": "^4.0.1",
    "tslib": "^1.9.0",
    "typedarray-to-buffer": "^3.1.5",
    "web3": "1.0.0-beta.37",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.1",
    "@angular-devkit/core": "0.8.1",
    "@angular/cli": "^7.1.0",
    "@angular/compiler-cli": "7.1.0",
    "@angular/language-service": "7.1.0",
    "@types/jasmine": "^2.8.12",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^6.14.2",
    "codelyzer": "^4.4.4",
    "jasmine-core": "^2.99.1",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^3.1.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.3",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.1",
    "protractor-console-plugin": "^0.1.1",
    "ts-node": "^3.3.0",
    "tslint": "^5.11.0",
    "typescript": "3.1.6",
    "webpack": "^4.26.1",
    "webpack-dev-server": "^3.1.10"
  }
}
karel
  • 5,489
  • 46
  • 45
  • 50
Dhruv Mistry
  • 445
  • 1
  • 4
  • 6

7 Answers7

33

Try this

Step 1:

$ npm cache clean --force

Step 2:

Delete node_modules by $ rm -rf node_modules also delete package-lock.json

Step 3:

Update the npm to the latest stable version

npm install -g npm@7.6.0

Step 3:

npm install

To start again,

$ npm start
Tanmoy Bhattacharjee
  • 1,040
  • 11
  • 21
  • 1
    worked for me, the thing that worked for me was updating the npm version. thank you! – jenkizenki Sep 30 '21 at 16:04
  • it dose not work for me, I am working on nextcloud app with vuejs front-end. – Navid_pdp11 Jan 13 '22 at 11:41
  • 2
    It's kind of useless w/o explanation how your command solves the issue... – Daniel Hornik Apr 08 '22 at 15:42
  • 3
    @DanielHornik aren't the NPM commands self explanatory? Step 1: cleans the cache, Step2: removes node_modules, Step3, updates the npm to the latest version, at the time of answering the version was 7.6.0 which was latest, step 4: start again. Explanation is: that npm is not full proof and sometimes the npm and the OS handshaking may fail. Sometimes if there are dormant / active threads that uses NPM, may block the cache clean up. – Tanmoy Bhattacharjee Apr 28 '22 at 03:20
  • if you are using nvm, there is an easier way to update npm to the latest version: `nvm install-latest-npm` – Saber Aug 12 '22 at 00:55
  • you can also use `n`, However, I have tried both, `n` and `nvm` but it did not work for me on my mac terminal. Though I have not invested more time to figure out why this has happened, after the OS update `n` is working as expected – Tanmoy Bhattacharjee Aug 16 '22 at 03:28
8

I just spent about 3 hours debugging this. What eventually worked for me was the following

nvm install 14
nvm use 14
npm install --legacy-peer-deps 
Make-HCI
  • 189
  • 3
  • 10
2

I got this error because I had a dependency that was referencing a fork with the version identifier github:author/repo#branch. Not sure if the branch name changed or what, but npm was no longer able to clone it.

I swapped back to the original version on npm and was able to npm install successfully.

Extra notes: This was in a Laravel Sail environment, and by running npm install from within the Docker container as the root user (sail root-shell) I got a more verbose error message telling me the exact dependency that was causing issues.

Ethan C
  • 1,408
  • 1
  • 14
  • 26
1

For anyone still looking for the answer, I faced this problem when updating my Mac to macOS Ventura 13.1.

After checking with brew doctor, I was surprised that xcode was missing.
Simply installing the xcode seemed to have solved the issue:

xcode-select --install
Kox
  • 834
  • 7
  • 12
0

I'm on In Windows 10 with node 16.

For me, the solution was either running commands

set NODE_ENV=development
$env:NODE_ENV="development"

or calling the npm install command with admin rights inside PowerShell

canbax
  • 3,432
  • 1
  • 27
  • 44
0

Upgrade your NPM:

npm install -g npm@latest

Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69
0

I ran into this same error while building a docker container with the Node 19-alpine base image. The error happened after I added a new package dependency of type "github:<package_name>" (the bin-build and bin-wrapper packages were being pulled in which I think caused the issue).

My Dockerfile is a multi-stage build.

I was able to prevent the error by using the full Node 19 image instead of the alpine image just for the dependency stage which is the first stage and which calls npm install. This did not affect the final size of the container.

Here's a shortened version of the Dockerfile to illustrate:

# Stage 1 - Gather dependencies
FROM node:19 AS deps
...
RUN npm ci
...

# Stage 2 - Runner
FROM node:19-alpine AS runner
...
CMD ["node", "index.js"]
...
blazeline
  • 339
  • 3
  • 8