npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.49k stars 3.17k forks source link

[BUG] npm ci failing for private package without name #1299

Closed Silic0nS0ldier closed 3 years ago

Silic0nS0ldier commented 4 years ago

What / Why

App/website projects have no need for a package name, so it is omitted. Recently (perhaps due to an environment change, dependency graph change, or npm update) the npm ci command has started crashing when close to completion (just before a postinstall script is run).

When

Whenever npm ci is run on an unnamed package.json.

Where

How

Current Behavior

npm ci completes installation of dependencies but crashes before postinstall script can be executed, reporting the following error (extract from the debug file).

(clipped)
9137 info lifecycle @babel/plugin-proposal-class-properties@7.8.3~postinstall: @babel/plugin-proposal-class-properties@7.8.3
9138 info lifecycle undefined@undefined~install: undefined@undefined
9139 info lifecycle undefined@undefined~postinstall: undefined@undefined
9140 verbose stack TypeError: Cannot read property 'length' of undefined
9140 verbose stack     at _incorrectWorkingDirectory (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:114:60)
9140 verbose stack     at /usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:86:44
9140 verbose stack     at /usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:218:12
9140 verbose stack     at callback (/usr/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:295:20)
9140 verbose stack     at FSReqCallback.oncomplete (fs.js:176:5)
9141 verbose cwd /home/silicon/source/kss/website
9142 verbose Linux 4.19.84-microsoft-standard
9143 verbose argv "/usr/bin/node" "/usr/bin/npm" "ci"
9144 verbose node v14.2.0
9145 verbose npm  v6.14.4
9146 error Cannot read property 'length' of undefined
9147 verbose exit [ 1, true ]
(end)

Steps to Reproduce

npm version: 6.9.0 node version: 10.16.2 npm i ; npm ci on the following package.json (only npm ci is affected by this bug)

{
    "private": true,
    "scripts": {
        "dev": "gulp dev",
        "local": "gulp local",
        "prod": "gulp production",
        "postinstall": "is-npm || npm i --package-lock-only"
    },
    "dependencies": {
        "awesomplete": "^1.1.5",
        "core-js": "^3.6.2",
        "create-react-class": "^15.6.3",
        "history": "^3.3.0",
        "intl-tel-input": "^17.0.0",
        "lodash": "^3.10.1",
        "moment": "^2.24.0",
        "prop-types": "^15.7.2",
        "react": "^15.6.2",
        "react-copy-to-clipboard": "^5.0.2",
        "react-dom": "^15.6.2",
        "react-js-pagination": "^3.0.3",
        "react-rating": "^1.7.2",
        "react-redux": "^4.4.10",
        "react-router": "^3.2.6",
        "redux": "^3.7.2",
        "redux-logger": "^2.10.2",
        "redux-simple-router": "0.0.10",
        "redux-thunk": "^1.0.3",
        "regenerator-runtime": "^0.13.5"
    },
    "devDependencies": {
        "@babel/core": "^7.9.6",
        "@babel/plugin-proposal-class-properties": "^7.8.3",
        "@babel/plugin-proposal-optional-chaining": "^7.9.0",
        "@babel/preset-env": "^7.9.6",
        "@babel/preset-react": "^7.9.4",
        "@rollup/plugin-babel": "^5.0.0",
        "@rollup/plugin-commonjs": "^11.1.0",
        "@rollup/plugin-node-resolve": "^7.1.3",
        "@types/awesomplete": "^1.1.10",
        "@types/googlemaps": "^3.39.3",
        "@types/intl-tel-input": "^14.0.1",
        "@types/jquery": "^3.3.34",
        "@types/jquery-mask-plugin": "^1.14.3",
        "@types/jquery.validation": "^1.16.6",
        "@types/jqueryui": "^1.12.10",
        "@types/lodash": "^3.10.2",
        "@types/react": "^15.6.28",
        "@types/react-js-pagination": "^3.0.3",
        "@types/react-redux": "^4.4.47",
        "@types/react-router": "^3.0.22",
        "babelify": "^10.0.0",
        "browserify": "^16.5.1",
        "del": "^5.1.0",
        "envify": "^4.1.0",
        "esm": "^3.2.25",
        "gulp": "^4.0.2",
        "gulp-changed": "^4.0.2",
        "gulp-clean-css": "^4.3.0",
        "gulp-clone": "^2.0.1",
        "gulp-concat": "^2.6.1",
        "gulp-concat-css": "^3.1.0",
        "gulp-filter": "^6.0.0",
        "gulp-if": "^3.0.0",
        "gulp-imagemin": "^6.2.0",
        "gulp-less": "^4.0.1",
        "gulp-replace": "^1.0.0",
        "gulp-sass": "^4.1.0",
        "gulp-sourcemaps": "^2.6.5",
        "gulp-streamify": "1.0.2",
        "gulp-terser": "^1.2.0",
        "gulp-webp": "^4.0.1",
        "is-npm-cli": "^1.0.0",
        "rollup": "^2.10.0",
        "rollup-plugin-terser": "^5.3.0",
        "through2": "^3.0.1",
        "vinyl-buffer": "^1.0.1",
        "vinyl-source-stream": "^2.0.0"
    },
    "engines": {
        "node": "^10 || ^12 || ^14"
    }
}

Expected Behavior

Missing optional package.json properties don't break installs.

Who

References

Silic0nS0ldier commented 4 years ago

Issue can still be reproduced under latest stable version. npm version: 6.14.8 node version: 14.14.0

9529 info lifecycle @babel/helper-compilation-targets@7.12.1~install: @babel/helper-compilation-targets@7.12.1
9530 info lifecycle @babel/helper-compilation-targets@7.12.1~postinstall: @babel/helper-compilation-targets@7.12.1
9531 info lifecycle @babel/preset-env@7.12.1~install: @babel/preset-env@7.12.1
9532 info lifecycle @babel/preset-env@7.12.1~postinstall: @babel/preset-env@7.12.1
9533 info lifecycle undefined@undefined~install: undefined@undefined
9534 info lifecycle undefined@undefined~postinstall: undefined@undefined
9535 verbose stack TypeError: Cannot read property 'length' of undefined
9535 verbose stack     at _incorrectWorkingDirectory (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:114:60)
9535 verbose stack     at /usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:86:44
9535 verbose stack     at /usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:218:12
9535 verbose stack     at callback (/usr/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:295:20)
9535 verbose stack     at FSReqCallback.oncomplete (fs.js:184:5)
9536 verbose cwd /home/silicon/source/npm-test
9537 verbose Linux 4.19.84-microsoft-standard
9538 verbose argv "/usr/bin/node" "/usr/bin/npm" "ci"
9539 verbose node v14.14.0
9540 verbose npm  v6.14.8
9541 error Cannot read property 'length' of undefined
9542 verbose exit [ 1, true ]

Worth noting that the dependency graph seems to affect this, a small unnamed package with a single dependency is unaffected for example.

Silic0nS0ldier commented 4 years ago

This issue is fixed in npm v7, however as it is currently hidden behind the 7 tag I'll leave this open for now.

darcyclarke commented 3 years ago

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is preproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.