babel-loader和webpack版本不一致,导致项目启动失败

使用create-react-app脚手架创建好一个项目之后,我的项目名称是my-react,在项目下使用npm start启动程序,但是在这一步出现错误

意思是说用create-react-app创建项目的时候所用到的babel-loader依赖是8.0.6版本的,但是在我所创建项目的node_modules下的babel-loader版本是7.1.5的版本。所以我要把版本升级才可以启动项目。

其实解决办法其实图上已经给出1-7点

  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/amy/Projects/HandheldWestLake/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.

我在发生错误之后我也搜索到相关的问题了,看到了解决办法如下:

但是结合自己的文件整理出来了如下几个步骤:

1.删除package-lock.json文件

2.删除你文件夹中的node_modules模块

3.卸载package.json文件中的babel-loader 即npm uninstall babel-loader

4.安装你用到的版本 npm install babel-loader@8.0.6的需要的是8.0.6。

但是我还是建议直接安装你所需要的版本,也就是第四步。

这里我们所注意的地方就是要按照错误信息提供的地址来进行安装版本。

我的是如下图:这里进行安装的地方并不是我们项目的地址。

以上就是这些问题。弄好后直接启动项目即可。 

babel-loder的问题刚解决,随后webpack也报了同样的问题

解决办法是一样的直接安装所需的版本就可以了

npm i -D webpack@4.40.2

 那么这样所有的问题都解决了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值