在做項(xiàng)目的時(shí)候出現(xiàn)一個(gè)問題戈泼,由于babel-loader版本號(hào)不一致報(bào)錯(cuò),報(bào)錯(cuò)如下圖:
圖中說:用create-react-app創(chuàng)建項(xiàng)目的時(shí)候所用到的babel-loader依賴是8.04版本驱还,但是在我創(chuàng)建項(xiàng)目的node_modules下的babel-loader版本是8.0.5版本的.
結(jié)果打開pakage.json和package-lock.json文件果然babel-loader版本不一樣
解決辦法其實(shí)第一張圖已經(jīng)給出1-7點(diǎn)
- 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.