无法在 Angular 项目中安装 npm 包
Posted
技术标签:
【中文标题】无法在 Angular 项目中安装 npm 包【英文标题】:Cannot install npm package in Angular project 【发布时间】:2020-09-17 03:00:06 【问题描述】:我从 GitLab 克隆了我的项目,我需要在我的项目中安装 NPM 包。
当我运行npm install
时,它显示了这个错误:
然后我去日志文件看看:
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 ]
这是我的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"
有什么问题?我该如何解决?
【问题讨论】:
当您是npm install
ing 时,您需要向我们展示您的package,json
而不是angular.json
19","dist":"integri
没有出现在angular.json
中,所以不清楚为什么要显示它。检查您拥有的其他 JSON 文件;以package,-lock.json
为例。
19","dist":"integri
也不在 package.json
中。查找包含该文本的文件,这就是无法解析的内容。
【参考方案1】:
实际上,您的 package-lock.json 中存在一些问题。因为 package-lock.json 会在该 json 中为每个依赖项插入一个完整性密钥。有时该 json 会变形/损坏,因此当 npm 下次去读取它以确定要安装哪个版本的依赖项时。它给出了这种错误。下面给出的步骤可以解决这个问题。
删除 package-lock.json。
删除节点模块
运行 npm cache clean --force
运行 npm install。
【讨论】:
【参考方案2】:尝试npm cache clean --force
,然后使用npm install
重新安装。
希望它有效! :)
【讨论】:
如果不行,请附上你的package.json文件以上是关于无法在 Angular 项目中安装 npm 包的主要内容,如果未能解决你的问题,请参考以下文章
无法在我的 Angular 项目中安装 tailwind css
我无法在我的Ionic项目文件夹中安装npm软件包并获得错误提示:没有存储库字段。没有许可证字段。怎么解决?
npm install:无法在 Windows 10 中安装依赖项