Angular npm install 有效,但 npm ci 出现错误

som*_*men 8 npm asp.net-core angular

我有一个托管 Angular 应用程序的 ASP.NET 核心应用程序的问题。

运行npm install正常,但npm ci不起作用并出现以下错误:

错误:

npm WARN prepare removing existing node_modules/ before installation
npm WARN lockfile Optional missing: fsevents@2.2.1
npm ERR! Cannot read property 'requires' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     XX\_logs\2020-04-30T13_32_04_555Z-debug.log
Run Code Online (Sandbox Code Playgroud)

调试日志文件:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'ci'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v12.15.0
4 verbose npm-session 92a2c0a95ca42a4b
5 info prepare initializing installer
6 verbose prepare starting workers
7 verbose prepare installation prefix: XX\ClientApps
8 verbose prepare using package-lock.json
9 warn prepare removing existing node_modules/ before installation
10 verbose checkLock verifying package-lock data
11 warn lockfile Optional missing: fsevents@2.2.1
12 verbose teardown shutting down workers.
13 info teardown Done in 0.001s
14 verbose stack TypeError: Cannot read property 'requires' of undefined
14 verbose stack     at addChild (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-logical-tree\index.js:128:24)
14 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\npm-logical-tree\index.js:113:5
14 verbose stack     at Array.forEach (<anonymous>)
14 verbose stack     at lockTree (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-logical-tree\index.js:107:5)
14 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\libcipm\index.js:144:21
15 verbose cwd C:\Repos\HMI4-2\Plugins\CommonPlugins\WebHmiPlugins\WebHmi.App\ClientApps
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "ci"
18 verbose node v12.15.0
19 verbose npm  v6.13.4
20 error Cannot read property 'requires' of undefined
21 verbose exit [ 1, true ]
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做,以及为什么 install 有效但 ci 没有。有人能帮我弄清楚 npm ci 崩溃的原因以及我如何解决这个错误吗?

编辑: fsevents 被定义为一个可选的依赖项:

    "optionalDependencies": {
        "fsevents": "2.2.1",
        "node-sass": "4.12.0",
        "protractor": "5.4.2",
        "ts-node": "8.4.1",
        "tslint": "5.20.0"
    }
Run Code Online (Sandbox Code Playgroud)

所以我认为-no-optional国旗会有所帮助。我 nuked node_modules 和 package-lock.json 运行npm install -no-optional,然后npm ci -no-optional. 除了运行安装时的一堆警告(见下文)外,我遇到了与上面相同的错误。

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: abbrev@1.1.1 (node_modules\@angular\compiler-cli\node_modules\fsevents\node_modules\abbrev):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename 'XX\ClientApps\node_modules\@angular\compiler-cli\node_modules\fsevents\node_modules\abbrev' -> 'XX\ClientApps\node_modules\@angular\compiler-cli\node_modules\fsevents\node_modules\.abbrev.DELETE'
Run Code Online (Sandbox Code Playgroud)

编辑2:

添加了以下日志记录/输出:

C:\Users\XX\AppData\Roaming\npm\node_modules\npm\node_modules\npm-logical-tree\index.js

npm WARN prepare removing existing node_modules/ before installation
npm WARN lockfile Optional missing: fsevents@2.2.1
npm ERR! Cannot read property 'requires' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     XX\_logs\2020-04-30T13_32_04_555Z-debug.log
Run Code Online (Sandbox Code Playgroud)

结果:

==============
LogicalTree {
  name: 'fsevents',
  version: undefined,
  address: 'fsevents',
  optional: false,
  dev: false,
  bundled: false,
  resolved: undefined,
  integrity: undefined,
  dependencies: Map {},
  requiredBy: Set {
    LogicalTree {
      name: 'XXMYAppName',
      version: '0.0.0',
      address: '',
      optional: false,
      dev: false,
      bundled: false,
      resolved: undefined,
      integrity: undefined,
      dependencies: [Map],
      requiredBy: Set {}
    }
  }
}
fsevents
undefined
npm ERR! Cannot read property 'requires' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\XX\AppData\Roaming\npm-cache\_logs\2020-05-05T08_35_18_624Z-debug.log
Run Code Online (Sandbox Code Playgroud)

编辑3:

包.json

{
    "name": "XX",
    "version": "0.0.0",
    "scripts": {
        "ng": "ng",
        "start": "echo Starting... && ng serve",
        "build": "ng build",
        "build-libs": "ng build core-lib && ng build dialog-lib && ng build services-lib && ng build components-lib",
        "build-app-dashboard": "ng build dashboard-app --base-href /dashboard/ --prod",
        "build-app-infeed": "ng build infeed-app --base-href /infeed/ --prod",
        "build-apps": "npm run build-app-dashboard && npm run build-app-infeed",
        "build-all": "npm run build-libs && npm run build-apps",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
    },
    "private": true,
    "//": [
        "Please use fixed versions instead of prefixing it with ~ or ^ or using 'latest'.",
        "Run command `npm outdated` to check whether newer versions are available."
    ],
    "dependencies": {
        "@angular/animations": "9.1.4",
        "@angular/cdk": "9.2.2",
        "@angular/common": "9.1.4",
        "@angular/compiler": "9.1.4",
        "@angular/core": "9.1.4",
        "@angular/flex-layout": "9.0.0-beta.29",
        "@angular/forms": "9.1.4",
        "@angular/material": "8.2.3",
        "@angular/platform-browser": "9.1.4",
        "@angular/platform-browser-dynamic": "9.1.4",
        "@angular/platform-server": "9.1.4",
        "@angular/router": "9.1.4",
        "@aspnet/signalr": "1.1.4",
        "@nguniversal/module-map-ngfactory-loader": "8.1.1",
        "@progress/kendo-angular-common": "1.2.1",
        "@progress/kendo-angular-gauges": "3.0.0",
        "@progress/kendo-angular-intl": "2.0.0",
        "@progress/kendo-angular-l10n": "2.0.1",
        "@progress/kendo-drawing": "1.6.0",
        "@progress/kendo-theme-default": "4.12.0",
        "aspnet-prerendering": "3.0.1",
        "bootstrap": "4.3.1",
        "core-js": "3.3.3",
        "jquery": "3.4.1",
        "moment": "2.24.0",
        "ngx-moment": "3.5.0",
        "oidc-client": "1.9.1",
        "popper.js": "1.16.0",
        "rxjs": "6.5.3",
        "tslib": "1.10.0",
        "zone.js": "0.10.2"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "0.901.4",
        "@angular-devkit/build-ng-packagr": "0.901.4",
        "@angular-devkit/schematics": "9.1.4",
        "@angular/cli": "9.1.4",
        "@angular/compiler-cli": "9.1.4",
        "@angular/language-service": "9.1.4",
        "@types/jasmine": "3.4.4",
        "@types/jasminewd2": "2.0.8",
        "@types/node": "12.11.1",
        "codelyzer": "5.1.2",
        "jasmine-core": "3.5.0",
        "jasmine-spec-reporter": "4.2.1",
        "karma": "4.4.1",
        "karma-chrome-launcher": "3.1.0",
        "karma-coverage-istanbul-reporter": "2.1.0",
        "karma-jasmine": "2.0.1",
        "karma-jasmine-html-reporter": "1.4.2",
        "ng-packagr": "^9.0.0",
        "nl2br-pipe": "1.2.3",
        "typescript": "3.8.3"
    },
    "optionalDependencies": {
        "fsevents": "2.2.1",
        "node-sass": "4.12.0",
        "protractor": "5.4.2",
        "ts-node": "8.4.1",
        "tslint": "5.20.0"
    }
}
Run Code Online (Sandbox Code Playgroud)

Las*_*uge 2

检查package-lock.json中的fsevents版本是否与package.json中的不匹配

npm ci 从 package-lock.json 进行验证。如果版本不匹配,它将退出并出现错误。但 npm install 只会查看 package.json 并开始将它们添加到 node_modules 中。如果 package-lock.json 中未提及版本,它将由 npm install 自动添加