Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular npm install works but npm ci gives errors

i've got an issue where I have an ASP.NET core app that hosts an Angular application.

running npm install works fine, however npm ci does not work and gives the following errors:

Error:

npm WARN prepare removing existing node_modules/ before installation
npm WARN lockfile Optional missing: [email protected]
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

Debug logfile:

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 [email protected]
3 info using [email protected]
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: [email protected]
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 ]

I'm clueless about what to do about this, and why install works but ci doesn't. Could anybody help me figure out why npm ci crashes and how i could resolve this error?

EDIT: fsevents is defined as an optional dependency:

    "optionalDependencies": {
        "fsevents": "2.2.1",
        "node-sass": "4.12.0",
        "protractor": "5.4.2",
        "ts-node": "8.4.1",
        "tslint": "5.20.0"
    }

So i thought the -no-optional flag would help. I nuked node_modules and package-lock.json ran npm install -no-optional and then npm ci -no-optional. Aside from a bunch of warnings (see below) when running the install, i had the same error as above.

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (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'

EDIT2:

Added the following logging/output:

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

function addChild (dep, tree, allDeps, pkgLock) {
  console.log("==============")
  tree.addDep(dep)
  console.log(dep)
  allDeps.set(dep.address, dep)
  const addr = dep.address
  console.log(addr)
  const lockNode = atAddr(pkgLock, addr)
  console.log(lockNode)
  Object.keys(lockNode.requires || {}).forEach(name => {
    const tdepAddr = reqAddr(pkgLock, name, addr)
    let tdep = allDeps.get(tdepAddr)
    if (!tdep) {
      tdep = makeNode(name, tdepAddr, atAddr(pkgLock, tdepAddr))
      addChild(tdep, dep, allDeps, pkgLock)
    } else {
      dep.addDep(tdep)
    }
  })
}

Result:

==============
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

EDIT3:

Packages.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"
    }
}
like image 795
sommmen Avatar asked Apr 30 '20 14:04

sommmen


2 Answers

The problem is with version of "fsevents" you have specified. Version "2.2.1" doesn't exists. Latest version of fsevents available in npmjs is "2.1.3".

npm install doesn't fails because you have specified fsevents in optionalDependencies. And npm install succeeds even if any optionalDependency fails.

But npm ci exits with an error if dependencies in package-lock.json do not match with those in package.json. So, instead of updating package-lock.json it will exit with an error.

One more thing, you are using --no-optional incorrectly. Notice the additional hypen(-) in --no-optional. Try adding version 2.1.3 for fsevents or try running npm ci --no-optional.

like image 95
monika Avatar answered Nov 22 '22 23:11

monika


Check whether the fsevents version in package-lock.json mismatches with in package.json

npm ci verifies from the package-lock.json. If the versions mismatch it will exit with an error. But npm install will only look into the package.json and start adding them to node_modules. if the version is not mentioned in package-lock.json it will be automatically added by npm install

like image 39
Lasanga Guruge Avatar answered Nov 22 '22 23:11

Lasanga Guruge