“npm ci”抛出异常:无法读取未定义的属性“长度”

2023-11-25

我在本地环境和 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最后几行:

11424信息生命周期@babel/[电子邮件受保护]~安装后:@babel/[电子邮件受保护]

第11425章 信息生命周期未定义@未定义~安装:未定义@未定义

11426 详细堆栈类型错误:无法读取未定义的属性“长度”

11426 _in CorrectWorkingDirectory 处的详细堆栈 (/home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:114:60)

11426 详细堆栈位于 /home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:86:44

11426 详细堆栈位于 /home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:218:12

11426 回调时的详细堆栈 (/home/vallo/.nvm/versions/node/v12.14.0/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:295:20)

11426 FSReqCallback.oncomplete 处的详细堆栈 (fs.js:159:5)

11427 详细 cwd /home/vallo/project

11428 详细 Linux 5.3.0-26-generic

第11429章 详细argv“/home/vallo/.nvm/versions/node/v12.14.0/bin/node”“/home/vallo/.nvm/versions/node/v12.14.0/bin/npm”“ci”

11430 详细节点 v12.14.0

11431 详细 npm v6.13.6

11432 错误 无法读取未定义的属性“长度”

11433 详细退出 [ 1, true ]

这是我的 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"
  }
}

我正在运行节点 12.14.0 和 npm 6.13.6


问题出在功能上_incorrectWorkingDirectory from npm-lifecycle,它不检查是否pkg.name为 null 因此会引发异常。

要解决此问题,请将“name”属性添加到package.json.

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“npm ci”抛出异常:无法读取未定义的属性“长度” 的相关文章