2

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

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

  • .tar从 npm 注册表 ( http://registry.npmjs.org/ )下载 react-dom文件并解压
  • 转到 react-dom 文件夹并运行npm install --production,但这会导致错误:

    react-dom dmitri$ npm install --production
    npm ERR! Darwin 15.3.0
    npm ERR! argv "node" "/usr/local/bin/npm" "install" "--production"
    npm ERR! node v0.12.7
    npm ERR! npm  v2.11.3
    
    npm ERR! Cannot read property 'react' of undefined
    npm ERR!
    npm ERR! If you need help, you may report this error at:
    npm ERR!     <https://github.com/npm/npm/issues>
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     /Users/dmitri/github/browserify-cdn-test/node_modules/react-dom/npm-debug.log
    

有趣,但如果在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!"
}
4

1 回答 1

3

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

它在 中不存在任何dependencies属性时出现package.jsonpeerDependencies存在并且npm install带有--production标志运行。最简单的复制方法:

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

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

于 2016-01-27T14:25:08.160 回答