我拿到了我的新笔记本电脑,想要开始反应编码。
首先,我尝试创建一个react模板目录。
npm install create-react-app
create-react-app template
现在npm开始在模板路径上正常工作。
然后我将此路径复制到新路径。
cp -r template 0429
这次npm开始不起作用。这是错误。
renderzdeMacBook-Pro:0429 renderz$ npm start
template@0.1.0 start /Users/renderz/myproject/0429
react-scripts start
module.js:472
throw err;
^
Error: Cannot find module '../scripts/start'
at Function.Module._resolveFilename (module.js:470:15)
at Function.resolve (internal/module.js:27:19)
at Object.<anonymous> (/Users/renderz/myproject/0429/node_modules/.bin/react-scripts:24:14)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:423:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! template@0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the template@0.1.0 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the template package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs template
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls template
npm ERR! There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/renderz/.npm/_logs/2017-04-29T10_00_45_104Z-debug.log
首先,我认为这将是&#39; react-scripts&#39;我安装了&#39; react-scripts&#39;全球化。但不能解决。
增加:
renderzdeMacBook-Pro:0429 renderz$ npm -v
4.5.0
renderzdeMacBook-Pro:0429 renderz$ node -v
v7.9.0
答案 0 :(得分:2)
如果使用start.js
复制项目,则手动运行cp -r
脚本:
node node_modules/react-scripts/scripts/start.js
因为cp -r
只复制文件内容,所以不一定保留符号链接。
npm start
使用react-scripts bin文件,该文件位于./node_modules/.bin/react-scripts
但是,这应该符号链接到./node_modules/react-scripts/bin/react-scripts.js
。这个符号链接意味着npm可以找到cross-spawn模块,它是react-scripts的子依赖项。
cp -a
将保留符号链接,以避免此问题。
查看this issue的更多详情。
希望这有帮助。