npm install for angular 7 个应用程序错误:无法从 .../.npm/_cacache/tmp 中找到模块“@angular-devkit/build-ng-packagr”
npm install for angular 7 app errors with: Could not find module "@angular-devkit/build-ng-packagr" from .../.npm/_cacache/tmp
我不是 JavaScript、node、npm、Angular 等方面的专家。我是 TypeScript 的新手。但是我继承了一个应用程序,我需要维护它来修复 cross-site cookie 问题。
所以,我正在尝试设置开发环境。我被困在 npm install 并抱怨找不到模块 @angular-devkit/build-ng-packagr。当我尝试显式安装该模块时,也会发生同样的错误。这是日志(省略了许多类似的行):
$ npm install @angular-devkit/build-ng-packagr
ngx-charts@0.0.0 prepack /home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2
npm run package
ngx-charts@0.0.0 package /home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2
npm run build:lib
ngx-charts@0.0.0 build:lib /home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2
ng build @swimlane/ngx-charts && npm run copy-files
Could not find module "@angular-devkit/build-ng-packagr" from "/home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2".
Error: Could not find module "@angular-devkit/build-ng-packagr" from "/home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2".
at Object.resolve (/usr/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:141:11)
at Observable.rxjs_1.Observable [as _subscribe] (/usr/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/src/architect.js:132:40)
at Observable._trySubscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:44:25)
at Observable.subscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:30:22)
at /usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:99:19
at new Promise (<anonymous>)
at Observable.toPromise (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:97:16)
at BuildCommand.initialize (/usr/lib/node_modules/@angular/cli/models/architect-command.js:88:94)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ngx-charts@0.0.0 build:lib: `ng build @swimlane/ngx-charts && npm run copy-files`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ngx-charts@0.0.0 build:lib script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kbuchs/.npm/_logs/2020-02-25T17_01_41_575Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ngx-charts@0.0.0 package: `npm run build:lib`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ngx-charts@0.0.0 package script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kbuchs/.npm/_logs/2020-02-25T17_01_41_608Z-debug.log
npm WARN tar ENOENT: no such file or directory, open '/home/kbuchs/git/host-analytics/node_modules/.staging/got-f7f3ba2c/package.json'
npm WARN tar ENOENT: no such file or directory, open '/home/kbuchs/git/host-analytics/node_modules/.staging/got-f7f3ba2c/index.js'
. . .
npm WARN @angular-devkit/build-ng-packagr@0.11.4 requires a peer of ng-packagr@^2.2.0 || ^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm ERR! premature close
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kbuchs/.npm/_logs/2020-02-25T15_51_50_301Z-debug.log
ngx-charts 的构建不知何故来自 package.json。 Package.json 定义了一些脚本,但我不知道什么会导致 npm 在我刚刚要求它安装时想要开始构建。
node_modules 中没有安装任何东西,顺便说一句,对于上述操作或我在下面描述的任何内容。
我会在底部插入我的 package.json。
我试过从头开始清理。我删除了 node_modules 目录。还删除了 ~/.npm/*。我使用节点版本 13 尝试了所有这些。
如果我重命名 package.json 和 package-lock.json 文件,我可以毫无问题地安装各个模块。对于那些具有原始名称的文件,我注意到在尝试显式安装特定模块时,npm 似乎 运行 通过为这些文件的内容构建完整的依赖关系树。
所以,接下来,我尝试回到大约 16 个月前首次创建项目时的当前节点版本,节点 10.19.0。我全局安装了 n 模块来执行此操作 (sudo npm install -g n)。这将 npm 的版本更改为 6.13.4。还是遇到了同样的结果。
我注意到接近尾声的警告关于 ng-packagr@^4.0.0 的对等依赖性并尝试安装它 (npm install ng-packagr@^4.0.0)。我得到了所有相同的错误,但关于 tsickle@>=0.34.0 的对等依赖的不同警告。再一次,我尝试了 npm install tsickle@>=0.34.0 并得到了所有相同的错误以及更多关于对 typescript@~3.7.2 的对等依赖的警告。所以,我做了 sudo npm install -g typescript@~3.7.2 ,它工作正常,没有错误或警告。当我回去尝试安装 tsickle 时,错误再次出现,并显示有关 peer 对 typescript 的依赖性的消息。感觉就像我在追我的尾巴。
谁能提出出路?
我的package.json:
{
"name": "analytics",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build.dev": "ng build -c dev",
"build.staging": "ng build -c staging",
"build.master": "ng build -c prod",
"deploy.dev": "cp app.dev.yaml dist/app.yaml && gcloud app deploy dist/app.yaml",
"deploy.staging": "cp app.staging.yaml dist/app.yaml && gcloud beta app deploy dist/app.yaml",
"deploy.master": "cp app.prod.yaml dist/app.yaml && gcloud beta app deploy dist/app.yaml",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/build-ng-packagr": "~0.11.1",
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"@ng-bootstrap/ng-bootstrap": "^4.0.0",
"@priotas/angular-bootstrap-slider": "^1.1.26",
"@swimlane/ngx-charts": "github:swimlane/ngx-charts#master",
"@types/date-fns": "^2.6.0",
"auth0-js": "^9.8.2",
"bootstrap": "^4.0.0-beta.3",
"bootstrap-slider": "^10.3.4",
"compact-timezone-list": "^1.0.6",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"date-fns": "^1.30.1",
"font-awesome": "^4.7.0",
"html2canvas": "^1.0.0-alpha.12",
"html2pdf": "0.0.11",
"jspdf": "^1.5.3",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"moment-timezone": "^0.5.23",
"ng-multiselect-dropdown": "^0.2.3",
"ng2-timezone-selector": "^0.2.4",
"ngx-webstorage-service": "^3.1.1",
"print-js": "^1.0.54",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular/cli": "~7.1.1",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/lodash": "^4.14.120",
"@types/node": "^8.10.45",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"ncp": "^2.0.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
}
因为这是一个 Angular 7 应用程序,这表明它是旧代码,这让我怀疑这可能不是一个有效的依赖项:
"@swimlane/ngx-charts": "github:swimlane/ngx-charts#master",
因为这将从 github 中提取 current 版本的 ngx-charts。查看版本,Angular 7.1.0 于 2018 年 11 月发布(参考:https://github.com/angular/angular-cli/releases/tag/v.7.1.0); so I'd try using a version of ngx-charts that was contemporary to that (it looks like 10.0.0 or 10.1.0 would be good bets, per https://github.com/swimlane/ngx-charts/releases)。
所以...为了安全起见:
rm -r package-lock.json node_modules
npm i --save @swimlane/ngx-charts@10.1.0
npm install
...看看是否能解决问题。
我不是 JavaScript、node、npm、Angular 等方面的专家。我是 TypeScript 的新手。但是我继承了一个应用程序,我需要维护它来修复 cross-site cookie 问题。
所以,我正在尝试设置开发环境。我被困在 npm install 并抱怨找不到模块 @angular-devkit/build-ng-packagr。当我尝试显式安装该模块时,也会发生同样的错误。这是日志(省略了许多类似的行):
$ npm install @angular-devkit/build-ng-packagr
ngx-charts@0.0.0 prepack /home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2
npm run package
ngx-charts@0.0.0 package /home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2
npm run build:lib
ngx-charts@0.0.0 build:lib /home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2
ng build @swimlane/ngx-charts && npm run copy-files
Could not find module "@angular-devkit/build-ng-packagr" from "/home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2".
Error: Could not find module "@angular-devkit/build-ng-packagr" from "/home/kbuchs/.npm/_cacache/tmp/git-clone-a312e0b2".
at Object.resolve (/usr/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:141:11)
at Observable.rxjs_1.Observable [as _subscribe] (/usr/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/src/architect.js:132:40)
at Observable._trySubscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:44:25)
at Observable.subscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:30:22)
at /usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:99:19
at new Promise (<anonymous>)
at Observable.toPromise (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:97:16)
at BuildCommand.initialize (/usr/lib/node_modules/@angular/cli/models/architect-command.js:88:94)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ngx-charts@0.0.0 build:lib: `ng build @swimlane/ngx-charts && npm run copy-files`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ngx-charts@0.0.0 build:lib script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kbuchs/.npm/_logs/2020-02-25T17_01_41_575Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ngx-charts@0.0.0 package: `npm run build:lib`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ngx-charts@0.0.0 package script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kbuchs/.npm/_logs/2020-02-25T17_01_41_608Z-debug.log
npm WARN tar ENOENT: no such file or directory, open '/home/kbuchs/git/host-analytics/node_modules/.staging/got-f7f3ba2c/package.json'
npm WARN tar ENOENT: no such file or directory, open '/home/kbuchs/git/host-analytics/node_modules/.staging/got-f7f3ba2c/index.js'
. . .
npm WARN @angular-devkit/build-ng-packagr@0.11.4 requires a peer of ng-packagr@^2.2.0 || ^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm ERR! premature close
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kbuchs/.npm/_logs/2020-02-25T15_51_50_301Z-debug.log
ngx-charts 的构建不知何故来自 package.json。 Package.json 定义了一些脚本,但我不知道什么会导致 npm 在我刚刚要求它安装时想要开始构建。
node_modules 中没有安装任何东西,顺便说一句,对于上述操作或我在下面描述的任何内容。
我会在底部插入我的 package.json。
我试过从头开始清理。我删除了 node_modules 目录。还删除了 ~/.npm/*。我使用节点版本 13 尝试了所有这些。
如果我重命名 package.json 和 package-lock.json 文件,我可以毫无问题地安装各个模块。对于那些具有原始名称的文件,我注意到在尝试显式安装特定模块时,npm 似乎 运行 通过为这些文件的内容构建完整的依赖关系树。
所以,接下来,我尝试回到大约 16 个月前首次创建项目时的当前节点版本,节点 10.19.0。我全局安装了 n 模块来执行此操作 (sudo npm install -g n)。这将 npm 的版本更改为 6.13.4。还是遇到了同样的结果。
我注意到接近尾声的警告关于 ng-packagr@^4.0.0 的对等依赖性并尝试安装它 (npm install ng-packagr@^4.0.0)。我得到了所有相同的错误,但关于 tsickle@>=0.34.0 的对等依赖的不同警告。再一次,我尝试了 npm install tsickle@>=0.34.0 并得到了所有相同的错误以及更多关于对 typescript@~3.7.2 的对等依赖的警告。所以,我做了 sudo npm install -g typescript@~3.7.2 ,它工作正常,没有错误或警告。当我回去尝试安装 tsickle 时,错误再次出现,并显示有关 peer 对 typescript 的依赖性的消息。感觉就像我在追我的尾巴。
谁能提出出路?
我的package.json:
{
"name": "analytics",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build.dev": "ng build -c dev",
"build.staging": "ng build -c staging",
"build.master": "ng build -c prod",
"deploy.dev": "cp app.dev.yaml dist/app.yaml && gcloud app deploy dist/app.yaml",
"deploy.staging": "cp app.staging.yaml dist/app.yaml && gcloud beta app deploy dist/app.yaml",
"deploy.master": "cp app.prod.yaml dist/app.yaml && gcloud beta app deploy dist/app.yaml",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/build-ng-packagr": "~0.11.1",
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"@ng-bootstrap/ng-bootstrap": "^4.0.0",
"@priotas/angular-bootstrap-slider": "^1.1.26",
"@swimlane/ngx-charts": "github:swimlane/ngx-charts#master",
"@types/date-fns": "^2.6.0",
"auth0-js": "^9.8.2",
"bootstrap": "^4.0.0-beta.3",
"bootstrap-slider": "^10.3.4",
"compact-timezone-list": "^1.0.6",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"date-fns": "^1.30.1",
"font-awesome": "^4.7.0",
"html2canvas": "^1.0.0-alpha.12",
"html2pdf": "0.0.11",
"jspdf": "^1.5.3",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"moment-timezone": "^0.5.23",
"ng-multiselect-dropdown": "^0.2.3",
"ng2-timezone-selector": "^0.2.4",
"ngx-webstorage-service": "^3.1.1",
"print-js": "^1.0.54",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular/cli": "~7.1.1",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/lodash": "^4.14.120",
"@types/node": "^8.10.45",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"ncp": "^2.0.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
}
因为这是一个 Angular 7 应用程序,这表明它是旧代码,这让我怀疑这可能不是一个有效的依赖项:
"@swimlane/ngx-charts": "github:swimlane/ngx-charts#master",
因为这将从 github 中提取 current 版本的 ngx-charts。查看版本,Angular 7.1.0 于 2018 年 11 月发布(参考:https://github.com/angular/angular-cli/releases/tag/v.7.1.0); so I'd try using a version of ngx-charts that was contemporary to that (it looks like 10.0.0 or 10.1.0 would be good bets, per https://github.com/swimlane/ngx-charts/releases)。
所以...为了安全起见:
rm -r package-lock.json node_modules
npm i --save @swimlane/ngx-charts@10.1.0
npm install
...看看是否能解决问题。