9

I'm getting this exception both on my local environment and in CircleCI.

> [email protected] postinstall /home/vallo/project/node_modules/core-js > node -e "try{require('./postinstall')}catch(e){}" npm ERR! Cannot read property 'length' of undefined npm ERR! A complete log of this run can be found in: npm ERR! /home/vallo/.npm/_logs/2020-01-16T20_12_00_564Z-debug.log 

/home/vallo/.npm/_logs/2020-01-16T20_12_00_564Z-debug.log last lines:

11424 info lifecycle @babel/[email protected]~postinstall: @babel/[email protected]

11425 info lifecycle undefined@undefined~install: undefined@undefined

11426 verbose stack TypeError: Cannot read property 'length' of undefined

11426 verbose stack at _incorrectWorkingDirectory (/home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:114:60)

11426 verbose stack at /home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:86:44

11426 verbose stack at /home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:218:12

11426 verbose stack at callback (/home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:295:20)

11426 verbose stack at FSReqCallback.oncomplete (fs.js:159:5)

11427 verbose cwd /home/vallo/project

11428 verbose Linux 5.3.0-26-generic

11429 verbose argv "/home/vallo/.nvm/versions/node/v12.14.0/bin/node" "/home/vallo/.nvm/versions/node/v12.14.0/bin/npm" "ci"

11430 verbose node v12.14.0

11431 verbose npm v6.13.6

11432 error Cannot read property 'length' of undefined

11433 verbose exit [ 1, true ]

This is my package.json:

{ "private": true, "scripts": { "install": "npx babel-node scripts/npm/install.js", "test": "npx babel-node scripts/npm/test.js", "lambda-test": "lambda/serverUnit.sh", "lint": "node_modules/.bin/eslint .", "flow": "flow; test $? -eq 0 -o $? -eq 2" }, "devDependencies": { "@babel/cli": "^7.4.4", "@babel/core": "^7.4.4", "@babel/node": "^7.2.2", "@babel/plugin-proposal-object-rest-spread": "^7.5.5", "@babel/plugin-transform-modules-commonjs": "^7.4.4", "@babel/plugin-transform-runtime": "^7.4.4", "@babel/polyfill": "^7.4.4", "@babel/preset-env": "^7.4.4", "@babel/preset-flow": "^7.0.0", "@babel/register": "^7.4.4", "@sanjo/jasmine-expect": "^1.0.1", "@sanjo/jasmine-spy": "^1.0.1", "@share911/babel-plugin-root-slash-import": "^1.2.0", "aws-sdk": "^2.521.0", "babel-eslint": "^10.0.3", "babel-loader": "^8.0.5", "babel-plugin-meteor-imports": "^1.0.3", "babelify": "^10.0.0", "browserify": "^16.2.3", "chai": "^4.2.0", "commander": "2.9.0", "eslint": "^6.3.0", "eslint-config-standard": "^14.1.0", "eslint-plugin-flowtype": "^4.3.0", "eslint-plugin-import": "^2.18.2", "eslint-plugin-node": "^10.0.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-react": "^7.14.3", "eslint-plugin-standard": "^4.0.1", "flow-bin": "^0.106.3", "jsdom": "^15.1.1", "jsdom-global": "^3.0.2", "json-loader": "^0.5.4", "karma": "^4.1.0", "karma-browserify": "^6.0.0", "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.3.0", "meteor": "./modules/meteor/", "meteor-promise": "^0.8.0", "mocha": "^6.1.4", "phantomjs-prebuilt": "^2.1.15", "proxyquire": "^1.7.10", "proxyquireify": "^3.2.0", "serverless": "^1.51.0", "sinon": "^7.3.2", "standard": "^12.0.1", "tingodb": "^0.6.1", "wallabify": "0.0.14", "watchify": "^3.11.1", "webpack": "^4.30.0", "webpack-node-externals": "^1.7.2" }, "dependencies": { "@babel/runtime": "^7.4.5", "aws-xray-sdk-core": "^2.3.5", "chai-as-promised": "^7.1.1", "json-to-pretty-yaml": "^1.2.2", "obj-resolve": "^1.0.4", "winston": "^3.2.1" } } 

I'm running node 12.14.0 and npm 6.13.6

2
  • Any luck with this? Seeing this 6.13.4 Commented Feb 7, 2020 at 1:55
  • Had to add name property to my package.json. This is a bug from NPM I guess. Answer posted. Commented Feb 7, 2020 at 11:45

1 Answer 1

39

Problem is on function _incorrectWorkingDirectory from npm-lifecycle, which does not check if pkg.name is null therefore throws an exception.

To fix this, add "name" property to package.json.

https://github.com/npm/npm-lifecycle/blob/latest/index.js#L114

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks so much. I still don't understand why name is required if I'm not publishing a package... but at least my builds will pass now 😅
Name shouldn't be required, its a bug and should be reported, but I failed to create a replicable minimal example. If you manage to, please add it as an issue on the github link I posted in the answer so it gets fixed.
awesome, works well for deploying to herokuapp (laravel and nodejs)
2022, the bug is still not fixed? wow, thanks for workaround btw

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.