[React]初始化React项目

本文根据开源内容派生,与公司无关。
派生自: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: [email protected]
npm ERR! Windows_NT 10.0.14393
npm ERR! argv “C:\Program Files\nodejs\node.exe” “C:\Users\*****\AppData\Roaming\npm\node_modules\npm\bin\np
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****\AppData\Roaming\npm-cache\iconv-lite\0.4.13\package.tgz.603192902
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename

npm ERR! Error: EPERM: operation not permitted, rename ‘C:\Users\sunru\AppData\Roaming\npm-cache\iconv-lite\0.4.13\packa
ge.tgz.603192902’ -> ‘C:\Users\sunru\AppData\Roaming\npm-cache\iconv-lite\0.4.13\package.tgz’
npm ERR! { Error: EPERM: operation not permitted, rename ‘C:\Users\sunru\AppData\Roaming\npm-cache\iconv-lite\0.4.13\pa
ckage.tgz.603192902’ -> ‘C:\Users\sunru\AppData\Roaming\npm-cache\iconv-lite\0.4.13\package.tgz’
npm ERR! errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘rename’,
npm ERR! path: ‘C:\Users\sunru\AppData\Roaming\npm-cache\iconv-lite\0.4.13\package.tgz.603192902’,
npm ERR! dest: ‘C:\Users\sunru\AppData\Roaming\npm-cache\iconv-lite\0.4.13\package.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:\GitCode\JavaScript\react-apps\npm-debug.log

经过实际测试,发现单独执行命令可以顺利解决问题,代码如下:

npm install -g react
npm install -g react-dom
npm install -g react-scripts

然后创建项目

create-react-app hello-world

猜你喜欢

转载自blog.csdn.net/greatbody/article/details/61616555