我尝试通过以下方式初始化react-native项目时发生错误:return
:
react-native init awesomeProject
然后我手动运行这个npm命令,错误就像在这里发生的那样:
Installing react-native package from npm...
`npm install --save react-native` failed
似乎是一个权限问题,我也使用npm verb afterAdd /Users/mc-zone/.npm/joi/6.9.1/package/package.json not in flight; writing
npm verb afterAdd /Users/mc-zone/.npm/joi/6.9.1/package/package.json written
npm ERR! git fetch -a origin (git://github.com/facebook/react.git) fatal: Unable to create temporary file '/Users/mc-zone/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b/./objects/pack/tmp_pack_XXXXXX': Permission denied
npm ERR! git fetch -a origin (git://github.com/facebook/react.git) fatal: index-pack failed
npm verb about to build /Users/mc-zone/_dev/rn/node_modules/react-native
npm verb unlock done using /Users/mc-zone/.npm/_locks/react-native-ce52a7d7697a2d98.lock for /Users/mc-zone/_dev/rn/node_modules/react-native
npm verb stack Error: Command failed: git fetch -a origin
npm verb stack fatal: Unable to create temporary file '/Users/mc-zone/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b/./objects/pack/tmp_pack_XXXXXX': Permission denied
npm verb stack fatal: index-pack failed
npm verb stack
npm verb stack at ChildProcess.exithandler (child_process.js:203:12)
npm verb stack at emitTwo (events.js:87:13)
npm verb stack at ChildProcess.emit (events.js:172:7)
npm verb stack at maybeClose (internal/child_process.js:818:16)
npm verb stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
npm verb cwd /Users/mc-zone/_dev/rn
npm ERR! Darwin 14.3.0
npm ERR! argv "/Users/mc-zone/.nvm/versions/node/v4.2.1/bin/node" "/Users/mc-zone/.nvm/versions/node/v4.2.1/bin/npm" "install" "react-native" "--save"
npm ERR! node v4.2.1
npm ERR! npm v2.14.7
npm ERR! code 128
npm ERR! Command failed: git fetch -a origin
npm ERR! fatal: Unable to create temporary file '/Users/mc-zone/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b/./objects/pack/tmp_pack_XXXXXX': Permission denied
npm ERR! fatal: index-pack failed
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm verb exit [ 1, true ]
仍无法正常工作。
此sudo chown -R $USER ~/.npm
由npm install
执行,因此我无法将react-native-cli
命令添加到sudo
(npm
仍然无法正常工作)< / p>
我该如何解决这个问题?
======
其他信息:
系统:Mac OS X 10.10.3
安装sudo react-native init
时,npm
安装了 nvm
。
node
由nvm
安装。
brew
还有我的文件夹权限(想要在$ npm -v
2.14.7
$ node -v
v4.2.1
中初始化应用程序):
_dev
答案 0 :(得分:0)
我遇到了同样的问题,并通过在已安装的文件夹中提供或获取权限来解决它:
➜ ~ sudo chmod 774 ProjectFolder/*
➜ ~ sudo chown Username ProjectFolder/*
➜ ~ sudo chmod 774 .babel.json
➜ ~ sudo chown Username .babel.json
答案 1 :(得分:0)
以下是创建新项目CRNA并从世博会开始运行的几个步骤。
步骤1:如果您已安装crna,请跳过此步骤 npm install -g create-react-native-app
step2:create-react-native-app AwesomeProject
step3:cd AwesomeProject
step4:npm start或yarn start
享受