在做项目的时候出现一个问题,由于babel-loader版本号不一致报错,报错如下图:
图中说:用create-react-app创建项目的时候所用到的babel-loader依赖是8.04版本,但是在我创建项目的node_modules下的babel-loader版本是8.0.5版本的.
结果打开pakage.json和package-lock.json文件果然babel-loader版本不一样
解决办法其实第一张图已经给出1-7点
- Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
- Delete node_modules in your project folder.
- Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
- 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: - 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. - 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. - 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.