使用npx(creact-react-app) 构建项目后-npm start启动报错

使用create-react-app创建的React项目时,有时在安装完其他组件后,再次运行 npm start 命令时会报以上错误,让我很郁闷,不过在上网搜了这个错后原来:

使用npx(creact-react-app) 构建项目后-npm start启动报错_第1张图片

create-react-app有丢包的缺陷,手动安装包后,需要重新npm install一下,这样node_modules/.bin/目录下才会重新出现react-scripts的文件,这样npm start命令才能正常执行。

步骤一

解决方案:

npm install react-scripts

npm install

安装完成后再次运行 npm start 即可
如果还是不能启动,那就 npm run eject 让配置文件可见 
npm start 启动

试过以上方法,无效可能我的情况不同:

C:\Users\Administrator\Desktop\ReactProject\my-app>npm start

> [email protected] start C:\Users\Administrator\Desktop\ReactProject\my-app
> react-scripts start


There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locall
y.

The react-scripts package provided by Create React App requires a dependency:

  "webpack": "4.41.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:

  C:\Users\Administrator\node_modules\webpack (version: 4.28.3)

Manually installing incompatible versions is known to cause hard-to-debug issues
.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .e
nv file in your project.
That will permanently disable this message but you might encounter other issues.


To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your proje
ct folder.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.js
on file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above st
eps with it instead.
     This may help because npm has known issues with package hoisting which may
get resolved in future versions.

  6. Check if C:\Users\Administrator\node_modules\webpack is outside your projec
t directory.
     For example, you might have accidentally installed something in your home f
older.

  7. Try running npm ls webpack in your project folder.
     This will tell you which other package (apart from the expected react-scrip
ts) installed webpack.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your pro
ject.
That would permanently disable this preflight check in case you want to proceed
anyway.

P.S. We know this message is long but please read the steps above :-) We hope yo
u find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-10-24T0
6_47_56_885Z-debug.log

步骤二

仔细阅读错误日志,会发现是create-react-app脚手架新版要求的webpack版本为[email protected],而我的当前版本为[email protected]

npm uninstall -g webpack
npm i [email protected]
npm uninstall -g webpack-cli
npm install -g webpack-cli

安装完成,再继续执行npm start 并没有什么用

npm start

使用npx(creact-react-app) 构建项目后-npm start启动报错_第2张图片

当我们在npm i 安装依赖的时候,会遇到这个Error: EBUSY: resource busy or locked, symlink....的问题。解决的 办法就是关掉电脑的杀毒软件,比如360 等等。

步骤三

刚开始我是按照 错误提示的 7个步骤来走,把文件一个个都删了,然后在yarn start 然后没解决,所以还是在项目文件夹中新建  .env文件,在文件中添加

SKIP_PREFLIGHT_CHECK=true ,然后在yarn start 就ok了

 

解决方法:

  在项目文件夹中新建  .env文件,在文件中添加 SKIP_PREFLIGHT_CHECK=true ,然后在yarn start 就ok了

结论:仔细看日志......

 


 

你可能感兴趣的:(react,webpack)