使用create-react-app脚手架创建好一个项目之后,我的项目名称是my-react,在项目下使用npm start启动程序,但是在这一步出现错误
意思是说用create-react-app创建项目的时候所用到的babel-loader依赖是8.0.6版本的,但是在我所创建项目的node_modules下的babel-loader版本是7.1.5的版本。所以我要把版本升级才可以启动项目。
其实解决办法其实图上已经给出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.
我在发生错误之后我也搜索到相关的问题了,看到了解决办法如下:
但是结合自己的文件整理出来了如下几个步骤:
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
那么这样所有的问题都解决了。