简体   繁体   中英

Cannot install npm package in Angular project

I clone my project from GitLab and I need to install the NPM packages in my project.

When I run npm install it shows me this error:

错误

and I go to the log file and see:

30601 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...19"},"dist":{"integri'
30601 verbose stack     at JSON.parse (<anonymous>)
30601 verbose stack     at parseJson (/usr/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
30601 verbose stack     at /usr/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50
30601 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:97:5)
30602 verbose cwd /home/mrcoder/Projects/Angular/Ava/PFA/pfa-front-cpl
30603 verbose Linux 5.4.0-33-generic
30604 verbose argv "/usr/bin/node" "/usr/bin/npm" "install"
30605 verbose node v12.17.0
30606 verbose npm  v6.14.4
30607 error Unexpected end of JSON input while parsing near '...19"},"dist":{"integri'
30608 verbose exit [ 1, true ]

This is my package.json :

{
  "name": "vex",
  "version": "9.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.0.7",
    "@angular/cdk": "~9.1.3",
    "@angular/common": "~9.0.7",
    "@angular/compiler": "~9.0.7",
    "@angular/core": "~9.0.7",
    "@angular/flex-layout": "9.0.0-beta.29",
    "@angular/forms": "~9.0.7",
    "@angular/material": "~9.1.3",
    "@angular/platform-browser": "~9.0.7",
    "@angular/platform-browser-dynamic": "~9.0.7",
    "@angular/router": "~9.0.7",
    "@iconify/icons-emojione": "~1.0.5",
    "@iconify/icons-fa-brands": "~1.0.10",
    "@iconify/icons-fa-solid": "~1.0.8",
    "@iconify/icons-ic": "~1.0.9",
    "@iconify/icons-logos": "~1.0.9",
    "@ngrx/store": "^9.1.2",
    "@ngx-loading-bar/core": "~5.0.0-alpha.1",
    "@ngx-loading-bar/router": "~5.0.0-alpha.1",
    "@ngx-translate/core": "^12.1.2",
    "@visurel/iconify-angular": "^0.0.7",
    "angular-calendar": "~0.28.5",
    "angular2-promise-buttons": "^4.0.6",
    "apexcharts": "~3.17.0",
    "color": "~3.1.2",
    "date-fns": "~2.11.0",
    "highlight.js": "~9.18.1",
    "jalali-moment": "^3.3.3",
    "luxon": "~1.22.0",
    "ng2-jalali-date-picker": "^2.3.0",
    "ngx-material-file-input": "^2.1.1",
    "ngx-quill": "~8.1.0",
    "ngx-showdown": "~5.1.0",
    "ngx-take-until-destroy": "~5.4.0",
    "ngx-toastr": "^12.0.1",
    "quill": "~1.3.7",
    "rxjs": "~6.5.4",
    "showdown": "^1.9.1",
    "simplebar": "~4.2.3",
    "tailwindcss": "~1.2.0",
    "tslib": "~1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "~9.0.0",
    "@angular-devkit/build-angular": "~0.900.7",
    "@angular/cli": "~9.0.7",
    "@angular/compiler-cli": "~9.0.7",
    "@angular/language-service": "~9.0.7",
    "@fullhuman/purgecss-loader": "^1.0.0",
    "@types/color": "~3.0.0",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/luxon": "~1.22.0",
    "@types/node": "~13.9.3",
    "@types/showdown": "~1.9.3",
    "@types/simplebar": "~5.1.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "postcss-loader": "~3.0.0",
    "postcss-scss": "~2.0.0",
    "protractor": "~5.4.0",
    "tailwindcss-dir": "~4.0.0",
    "ts-node": "^8.8.1",
    "tslint": "~5.15.0",
    "typescript": "~3.7.5"
  }
}

What's the problem? How can I solve it?

Actually you are having some issue in your package-lock.json. Because package-lock.json inserts a integrity key with each dependency in that json. Sometimes that json gets disformed/corrupted so when npm goes to read it next time to figure out what version of dependency to install. It gives this kind of error. The steps given below can resolve this issue.

  1. Delete package-lock.json.

  2. Delete node_modules

  3. Run npm cache clean --force

  4. Run npm install.

Try npm cache clean --force and then reinstall using npm install .

Hope it works: :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM