npm install with --production 选项和对等依赖项

npm install with --production option and peer dependencies

我正在使用 npm v2,出于某些特定原因,我需要将 react-dom 与 browserify 捆绑在一起。

但是我在安装它的依赖项时遇到了问题。我的步数:

有趣,但如果 运行 npm install 没有 --production 标志,它会得到对等依赖而不会出错。

任何解决方法?

更新 发布npm-debug.log 文件内容:

    cat /Users/dmitri/github/react-dom-tar/npm-debug.log
    0 info it worked if it ends with ok
    1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', '--production' ]
    2 info using npm@2.11.3
    3 info using node@v0.12.7
    4 verbose readDependencies loading dependencies from /Users/dmitri/github/react-dom-tar/package.json
    5 verbose install where, deps [ '/Users/dmitri/github/react-dom-tar', [] ]
    6 verbose stack TypeError: Cannot read property 'react' of undefined
    6 verbose stack     at /usr/local/lib/node_modules/npm/lib/install.js:179:33
    6 verbose stack     at Array.forEach (native)
    6 verbose stack     at /usr/local/lib/node_modules/npm/lib/install.js:178:50
    6 verbose stack     at /usr/local/lib/node_modules/npm/lib/install.js:367:22
    6 verbose stack     at evalmachine.<anonymous>:263:20
    6 verbose stack     at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:141:5)
    6 verbose stack     at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:61:22)
    6 verbose stack     at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)
    7 verbose cwd /Users/dmitri/github/react-dom-tar
    8 error Darwin 15.3.0
    9 error argv "node" "/usr/local/bin/npm" "install" "--production"
    10 error node v0.12.7
    11 error npm  v2.11.3
    12 error Cannot read property 'react' of undefined
    13 error If you need help, you may report this error at:
    13 error     <https://github.com/npm/npm/issues>
    14 verbose exit [ 1, true ]

更新 package.json 文件内容:

{
  "name": "react-dom",
  "version": "0.14.6",
  "description": "React package for working with the DOM.",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/facebook/react.git"
  },
  "keywords": [
    "react"
  ],
  "license": "BSD-3-Clause",
  "bugs": {
    "url": "https://github.com/facebook/react/issues"
  },
  "homepage": "https://github.com/facebook/react/tree/master/npm-react-dom",
  "peerDependencies": {
    "react": "^0.14.6"
  },
  "scripts": {
    "start": "node server.js"
  },
  "_id": "react-dom@0.14.6",
  "_shasum": "46d4e3243884f277e89ce8759131e8a16ac23e65",
  "_resolved": "https://registry.npmjs.org/react-dom/-/react-dom-0.14.6.tgz",
  "_from": "react-dom@*",
  "_npmVersion": "2.14.15",
  "_nodeVersion": "4.2.2",
  "_npmUser": {
    "name": "zpao",
    "email": "paul@oshannessy.com"
  },
  "maintainers": [
    {
      "name": "spicyj",
      "email": "ben@benalpert.com"
    },
    {
      "name": "zpao",
      "email": "paul@oshannessy.com"
    }
  ],
  "dist": {
    "shasum": "46d4e3243884f277e89ce8759131e8a16ac23e65",
    "tarball": "http://registry.npmjs.org/react-dom/-/react-dom-0.14.6.tgz"
  },
  "directories": {},
  "readme": "ERROR: No README data found!"
}

所以经过调查,很明显这是一个 NPM 错误 - https://github.com/npm/npm/issues/6581

package.json中没有dependencies属性,有peerDependenciesnpm install有运行时出现--production 标志。最简单的重现方式:

 echo '{"peerDependencies": { "npm": "*" } }' > package.json
 npm install --production

为了安全起见,在修复之前,包维护者需要将空对象添加到 dependencies: {}.