babel-loader版本不一致报错

在做项目的时候出现一个问题,由于babel-loader版本号不一致报错,报错如下图:

图中说:用create-react-app创建项目的时候所用到的babel-loader依赖是8.04版本,但是在我创建项目的node_modules下的babel-loader版本是8.0.5版本的.
npm报错.png

结果打开pakage.json和package-lock.json文件果然babel-loader版本不一样


json.png
lock.png
解决办法其实第一张图已经给出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.04我的需要的是8.04
5.npm start启动项目
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容