Node.js 获得';不变性';创建react本机项目时未找到错误
我才刚开始学习react native。我试过书中提到的东西 但是在运行Node.js 获得';不变性';创建react本机项目时未找到错误,node.js,macos,react-native,Node.js,Macos,React Native,我才刚开始学习react native。我试过书中提到的东西 但是在运行react native init AwesomeProject时 我得到以下错误 module.js:328 throw err; ^ Error: Cannot find module 'invariant' at Function.Module._resolveFilename (module.js:326:15) at Function.Module._load (module.js
react native init AwesomeProject
时
我得到以下错误
module.js:328
throw err;
^
Error: Cannot find module 'invariant'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/aragorn/AwesomeProject/node_modules/react-native/packager/react-packager/src/node-haste/Module.js:18:19)
at Module._compile (module.js:410:26)
at loader (/Users/aragorn/AwesomeProject/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/aragorn/AwesomeProject/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
module.js:328
犯错误;
^
错误:找不到模块“不变量”
在Function.Module.\u解析文件名(Module.js:326:15)
在Function.Module.\u加载(Module.js:277:25)
at Module.require(Module.js:354:17)
根据需要(内部/module.js:12:17)
反对。(/Users/aragorn/AwesomeProject/node_modules/react native/packager/react packager/src/node haste/Module.js:18:19)
在模块处编译(Module.js:410:26)
在加载程序中(/Users/aragorn/AwesomeProject/node_modules/babel register/lib/node.js:144:5)
at Object.require.extensions.(匿名函数)[as.js](/Users/aragorn/AwesomeProject/node_modules/babel register/lib/node.js:154:7)
在Module.load(Module.js:344:32)
在Function.Module.\u加载(Module.js:301:12)
我正在Mac OSX(约塞米蒂)上尝试以下配置:-
有人能帮我一下吗?我通过完全卸载node解决了这个问题。我在Mac上安装了带有web包的node,因此需要手动执行此操作:
Manual:
sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
Brew:
brew uninstall node
使用brew重新安装:
brew install node
我在对链接执行此操作时收到一个错误。我试过:
brew link node
brew link --overwrite node
我得到了一个权限错误,很可能是由于上面的sudo rm
。我不确定这是否会破坏任何东西,但这是我在其他线程上找到的解决方案
sudo chown -R $USER /usr/local
然后brew链接--覆盖节点
工作。在重新安装react-nativereact-native init
之后,它正在创建项目
我希望这有帮助。看看这个问题:
我试图遵循rogueSnake的建议:
npm i --save-dev invariant
而且对我有效这对我有效npm i-g不变量你能解释一下你的答案吗?我和哈基拉特·萨利亚遇到了同样的问题。经过一番搜索,我从ErmannoS那里找到了这个答案:
npmi--save dev invariant
。但是我决定尝试安装invariant
全局npmi-ginvariant
。在我这样做之后,我的项目成功地创建了,没有任何错误。