npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm ci fails with obscure error on nested packages if package.json omits name

What I Wanted to Do

Create a monorepo where “npm ci” in the root directory would install dependencies in each subpackage as well

What Happened Instead

The command failed with error:

dave@crypt:~/wikisophia/code/test$ npm ci
npm WARN prepare removing existing node_modules/ before installation
npm ERR! Cannot read property 'length' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dave/.npm/_logs/2019-02-26T23_33_04_653Z-debug.log

Reproduction Steps

Put this package.json in a directory:

  "private": true,
  "scripts": {
    "install": "cd subdirectory && npm install"
  "devDependencies": {
    "wrappy": "^1.0.2"

Put this package.json inside subdirectory.

  "private": true,
  "devDependencies": {
    "wrappy": "^1.0.2"

Run npm install to generate some package-lock.json files. Then run npm ci to see the error.


The npm-debug.log has:

24 info lifecycle wrappy@1.0.2~preinstall: wrappy@1.0.2
25 info lifecycle wrappy@1.0.2~install: wrappy@1.0.2
26 info lifecycle wrappy@1.0.2~postinstall: wrappy@1.0.2
27 info lifecycle undefined@undefined~install: undefined@undefined
28 verbose stack TypeError: Cannot read property 'length' of undefined
28 verbose stack     at _incorrectWorkingDirectory (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:99:60)
28 verbose stack     at /usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:71:44
28 verbose stack     at /usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:202:12
28 verbose stack     at /usr/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:285:20
28 verbose stack     at FSReqCallback.oncomplete (fs.js:159:5)
29 verbose cwd /home/dave/wikisophia/code/test
30 verbose Linux 4.15.0-45-generic
31 verbose argv "/usr/bin/node" "/usr/bin/npm" "ci"
32 verbose node v11.10.0
33 verbose npm  v6.7.0
34 error Cannot read property 'length' of undefined

Platform Info

$ npm --versions
dave@crypt:~/wikisophia/code/test$ npm --versions
{ npm: '6.7.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.1.1',
  modules: '67',
  napi: '4',
  nghttp2: '1.34.0',
  node: '11.10.0',
  openssl: '1.1.1a',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.26.0',
  v8: '',
  zlib: '1.2.11' }

$ node -p process.platform

The difference seems to be that npm install uses normalize-package-data while npm ci doesn’t.