【问题标题】:npm install for angular 7 app errors with: Could not find module "@angular-devkit/build-ng-packagr" from .../.npm/_cacache/tmpnpm install for angular 7 app 错误:从 .../.npm/_cacache/tmp 找不到模块“@angular-devkit/build-ng-packagr”
【发布时间】:2020-06-09 13:01:42
【问题描述】:

我不是 JavaScript、node、npm、Angular 等方面的专家。我是 TypeScript 的新手。但是我继承了一个应用程序,我需要对其进行维护以解决跨站点 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 时,又出现了错误,并且出现了关于对等依赖于 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"
  }
}

【问题讨论】:

    标签: node.js angularjs typescript npm npm-install


    【解决方案1】:

    由于这是一个 Angular 7 应用程序,这表明它是旧代码,这让我怀疑这可能不是一个有效的依赖项:

    "@swimlane/ngx-charts": "github:swimlane/ngx-charts#master",
    

    因为这将从 github 中提取 当前 版本的 ngx-charts。查看版本,Angular 7.1.0 于 2018 年 11 月发布(参考:https://github.com/angular/angular-cli/releases/tag/v.7.1.0);所以我会尝试使用与它同时代的 ngx-charts 版本(看起来 10.0.0 或 10.1.0 会是不错的选择,每 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
    

    ...看看这能不能解决问题。

    【讨论】:

    • 是的,成功了。我有一些对等依赖项需要解决: npm install -save @angular/cdk@7.x d3@^4.10.2 d3-scale@^1.0.6 popper.js@^1.14.3 @angular/common@^6.0 .0 @angular/core@^6.0.0 @angular/core@^5.0.0 rxjs@^5.1.0 现在,有一些漏洞需要修复,但一旦我开始构建和测试,我会解决这些问题去。谢谢,@贾斯汀
    猜你喜欢
    • 2023-02-16
    • 2021-05-24
    • 1970-01-01
    • 2018-10-28
    • 2020-01-14
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    相关资源
    最近更新 更多