简体   繁体   English

create-react-app 总是抛出 babel 错误

[英]create-react-app always throws babel error

Every time I create a create-react-app project it throws this error:每次我创建一个 create-react-app 项目时,它都会抛出这个错误:

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

  "babel-loader": "8.0.4"

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/dalegrant/Desktop/hyberchat-dashboard/client/node_modules/babel-loader (version: 8.0.5)

I have tried downgrading to 8.0.4,我试过降级到 8.0.4,

I've tried installing 8.0.5我试过安装 8.0.5

I've even made sure all my dependencies for babel rely on a 8.0.5!我什至确保我对 babel 的所有依赖都依赖于 8.0.5!

I have no idea what to do from here as the error persists for every create react app I now build!我不知道从这里开始做什么,因为我现在构建的每个 create react 应用程序都存在错误!

This must be a common problem, does anybody have an idea on how to get around this?!这一定是一个普遍的问题,有没有人知道如何解决这个问题?!

在您的机器用户文件夹中,有一个node_modules目录和package-lock.json使用rm -rf User/node_modulesrm -rf User/package-lock.json删除node_module ,然后删除您的node_module目录和pack-lock.json文件项目再次运行npm install然后它就可以工作了

Remove the babel-loader package (also globally):删除 babel-loader 包(也是全局的):

  npm uninstall babel-loader
  npm uninstall babel-loader -g

Then run create-react-app again, it should install the correct dependency.然后再次运行create-react-app ,它应该安装正确的依赖项。

If you use the babel-loader somewhere else, pin the dependency there to ensure this problem does not happen again.如果您在其他地方使用 babel-loader, 请将依赖项固定在那里以确保不会再次发生此问题。

you probably installed node_modules in your main folders before.您之前可能在主文件夹中安装了node_modules Search for them and remove.搜索它们并删除。 In my case i have installed node_modules on my Home folder.就我而言,我已经在我的主文件夹中安装了node_modules When i removed files from this directory problem disapeared当我从此目录中删除文件时,问题消失了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM