本文根据开源内容派生,与公司无关。
派生自:https://facebook.github.io/react/docs/installation.html
为什么要配置
开发环境配置是开发和学习开发的基础,没有提供这方面的配置信息就是耍流氓。
配置步骤
前提条件
- 安装了nodejs
- 支持npm
- npm配置正确可以访问外网
运行命令
npm install -g create-react-app
create-react-app hello-world
cd hello-world
npm start
以上是官方的命令,但是发现本地运行报错:
npm WARN optional Skipping failed optional dependency /react-scripts/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.17
npm ERR! Windows_NT 10.0.14393
npm ERR! argv “C:Program Filesnodejsnode.exe” “C:Users*****AppDataRoamingnpmnode_modulesnpmbinnp
m-cli.js” “install” “–save” “–save-exact” “react” “react-dom” “react-scripts”
npm ERR! node v7.7.1
npm ERR! npm v3.8.9
npm ERR! path C:Users****AppDataRoamingnpm-cacheiconv-lite .4.13package.tgz.603192902
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted,rename ‘C:UserssunruAppDataRoamingnpm-cacheiconv-lite .4.13packa
ge.tgz.603192902’ -> ‘C:UserssunruAppDataRoamingnpm-cacheiconv-lite .4.13package.tgz’
npm ERR! { Error: EPERM: operation not permitted,rename ‘C:UserssunruAppDataRoamingnpm-cacheiconv-lite .4.13pa
ckage.tgz.603192902’ -> ‘C:UserssunruAppDataRoamingnpm-cacheiconv-lite .4.13package.tgz’
npm ERR! errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘rename’,
npm ERR! path: ‘C:UserssunruAppDataRoamingnpm-cacheiconv-lite .4.13package.tgz.603192902’,
npm ERR! dest: ‘C:UserssunruAppDataRoamingnpm-cacheiconv-lite .4.13package.tgz’,
npm ERR! parent: ‘whatwg-encoding’ }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! E:GitCodeJavaScriptreact-appsnpm-debug.log
经过实际测试,发现单独执行命令可以顺利解决问题,代码如下:
npm install -g react
npm install -g react-dom
npm install -g react-scripts
然后创建项目
create-react-app hello-world