简体   繁体   English

无法在 Angular 项目中安装 npm package

[英]Cannot install npm package in Angular project

I clone my project from GitLab and I need to install the NPM packages in my project.我从 GitLab 克隆我的项目,我需要在我的项目中安装 NPM 包。

When I run npm install it shows me this error:当我运行npm install时,它显示了这个错误:

错误

and I go to the log file and see:我将 go 写入日志文件并查看:

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 :这是我的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.实际上,您的 package-lock.json 有一些问题。 Because package-lock.json inserts a integrity key with each dependency in that json.因为 package-lock.json 在 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.有时 json 会变形/损坏,所以当 npm 下次去阅读它以确定要安装哪个版本的依赖项时。 It gives this kind of error.它给出了这种错误。 The steps given below can resolve this issue.下面给出的步骤可以解决这个问题。

  1. Delete package-lock.json.删除 package-lock.json。

  2. Delete node_modules删除 node_modules

  3. Run npm cache clean --force运行 npm 缓存清理 --force

  4. Run npm install.运行 npm 安装。

Try npm cache clean --force and then reinstall using npm install .尝试npm cache clean --force然后使用npm install重新安装。

Hope it works: :)希望它有效::)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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