简体   繁体   English

npm run dev not working with webpack/babel 冲突

[英]npm run dev not working with webpack/babel conflict

I am trying to run npm run dev for a Vue project but I keep getting the following output:我正在尝试为 Vue 项目运行npm run dev但我不断收到以下 output:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: babel-loader@7.1.5
npm ERR! Found: webpack@5.75.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^5.0.0" from css-loader@6.7.2
npm ERR!   node_modules/css-loader
npm ERR!     dev css-loader@"^6.7.2" from the root project
npm ERR!   peer webpack@"^5.20.0" from html-webpack-plugin@5.5.0
npm ERR!   node_modules/html-webpack-plugin
npm ERR!     dev html-webpack-plugin@"^5.5.0" from the root project
npm ERR!   8 more (postcss-loader, terser-webpack-plugin, url-loader, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"2 || 3 || 4" from babel-loader@7.1.5
npm ERR! node_modules/babel-loader
npm ERR!   dev babel-loader@"^7.1.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"2 || 3 || 4" from babel-loader@7.1.5
npm ERR!   node_modules/babel-loader
npm ERR!     dev babel-loader@"^7.1.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

I have no idea what to do, I have tried uninstalling vue-cli and tried re-installing it (I'm not sure if this messed up my packages).我不知道该怎么做,我尝试卸载 vue-cli 并尝试重新安装它(我不确定这是否弄乱了我的包)。 Is there a way to cleanly delete everything and start fresh?有没有办法彻底删除所有内容并重新开始? If anyone can help that would be much appreciated!如果有人可以提供帮助,将不胜感激!

Update: I tried starting a new project with vue init webpack frontend in a new folder and tried installing axios and am getting the following error更新:我尝试在新文件夹中使用vue init webpack frontend启动一个新项目并尝试安装 axios 并收到以下错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: vuex@4.1.0
npm ERR! Found: vue@2.7.14
npm ERR! node_modules/vue
npm ERR!   vue@"^2.5.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^3.2.0" from vuex@4.1.0
npm ERR! node_modules/vuex
npm ERR!   vuex@"^4.1.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: vue@3.2.45
npm ERR! node_modules/vue
npm ERR!   peer vue@"^3.2.0" from vuex@4.1.0
npm ERR!   node_modules/vuex
npm ERR!     vuex@"^4.1.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

I recently updated my version of node (v19.1.0) and npm (v8.19.3), could that be an issue?我最近更新了我的节点版本 (v19.1.0) 和 npm (v8.19.3),这会是个问题吗? It generally seems like I am getting a bunch of conflicts every time I try to install new packages.每次我尝试安装新软件包时,似乎都会遇到一堆冲突。 Is there a way to just start clean?有没有办法开始清洁?

Probably one of your packages is outdated, according to the error.根据错误,可能您的某个软件包已过时。 I guess it's the babel loader.我猜这是 babel 加载器。

  • Method 1 Upgrading or Updating your packages might solve the dependency error.方法 1升级或更新您的包可能会解决依赖性错误。
  • Method 2 Try running npm install --force or npm install --legacy-peer-deps .方法 2尝试运行npm install --forcenpm install --legacy-peer-deps It should work.它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM