我使用的是npm v2,由于某些特定原因,我需要将react-dom与browserify捆绑在一起。
但是我遇到了安装它的问题。依赖。我的步骤:
.tar
文件并解压缩转到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!"
}
答案 0 :(得分:1)
因此,经过调查后,很明显这是一个NPM错误 - https://github.com/npm/npm/issues/6581
如果dependencies
中没有package.json
属性,peerDependencies
存在且npm install
以--production
标志运行,则会显示。最简单的方法:
echo '{"peerDependencies": { "npm": "*" } }' > package.json
npm install --production
为了安全起见,修补程序包维护者需要将空对象添加到 dependencies: {}
。