【发布时间】:2021-05-30 21:27:29
【问题描述】:
我不知道为什么,但我得到一个 babel 依赖相关的错误:
> yarn start yarn run v1.22.10 $ 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
> locally.
>
> The react-scripts package provided by Create React App requires a
> dependency:
>
> "babel-loader": "8.1.0"
>
> Don't try to install it manually: your package manager does it
> automatically. However, a different version of babel-loader was
> detected higher up in the tree:
>
> /Users/ri/node_modules/babel-loader (version: 8.0.6)
>
> 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 .env 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 project folder.
> 2. Delete node_modules in your project folder.
> 3. Remove "babel-loader" from dependencies and/or devDependencies in the package.json 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 steps with it instead.
> This may help because npm has known issues with package hoisting which may get resolved in future versions.
>
> 6. Check if /Users/ri/node_modules/babel-loader is outside your project directory.
> For example, you might have accidentally installed something in your home folder.
>
> 7. Try running npm ls babel-loader in your project folder.
> This will tell you which other package (apart from the expected react-scripts) installed babel-loader.
>
> If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file
> in your project. 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 you find them helpful!
我阅读了有关此问题的其他解决方案并执行了以下解决方案:Problems with babel loader in react-create-app
我尝试了以下方法:
- 删除节点模块、package.json.lock 和 yarn.lock 文件
- 我也试过在package.json中删除babel的依赖。
- 尝试了 Stackover 流程链接中提到的步骤
- 即使尝试完全创建新的 React 项目两次,但我仍然遇到相同的 babel 问题。我正在使用纱线 1.22.10。
- 我什至尝试将 react-scripts 更新到最新版本。
当我尝试使用命令 babel-loader --version 时,我得到以下结果:
my-app@0.1.0 /Users/ri/Desktop/my-app
└─┬ react-scripts@4.0.3
└── babel-loader@8.1.0
我通过以下步骤安装/创建了 react 项目:
npx create-react-app my-app
cd my-app
yarn start
有人可以帮助解释为什么这个问题仍然存在吗?
【问题讨论】:
-
根据您那里的信息,
babel-loader安装在/Users/ri/Desktop/my-app/node_modules和/Users/ri/node_modules中。后者可能是 global 安装,或者您直接在主目录中创建了一个项目。您描述的任何步骤都无法解决该问题 - 您需要从主目录中删除babel-loader(或完全删除node_modules/),或将项目移动到主目录外部的某个位置。 -
谢谢,这解决了我的问题 :) @jonrsharpe
标签: reactjs