You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法解析babel-loader模块问题求助:多种尝试后仍未解决

Fix for "Module not found: Error: Cannot resolve module 'babel-loader'"

Hey there, let's get this babel-loader issue sorted out. Looking at your package.json and webpack.config.js, the root problem is a version mismatch between Babel core packages and babel-loader—here's how to fix it step by step:

Key Issue Identified

You're using babel-loader@8.0.5 (which requires Babel 7.x) but paired it with babel-core@6.26.3 (Babel 6.x). These versions aren't compatible, which is why Webpack can't resolve the module correctly.

Step 1: Clean Up Old Babel Dependencies

First, uninstall the outdated Babel 6 packages that don't work with your babel-loader version:

npm uninstall babel-core babel-preset-env babel-preset-es2015 babel-preset-react

Step 2: Install Babel 7 Compatible Packages

Install the correct Babel 7 core and preset packages, along with the matching babel-loader:

npm install --save-dev @babel/core @babel/preset-env @babel/preset-react babel-loader@8.x

Step 3: Update Webpack Config

Your webpack.config.js uses Babel 6 preset names, which need to be updated to the Babel 7 scoped package names. Modify the module.rules section like this:

module: {
  rules: [
    {
      test: /\.jsx?$/,
      exclude: /node_modules/,
      loader: 'babel-loader',
      query: {
        presets: ['@babel/preset-env', '@babel/preset-react'] // Updated preset names
      }
    }
  ]
}

Step 4: Reset Dependencies & Cache

To ensure no leftover cached files or mismatched packages cause issues:

  • On Windows:
    rmdir /s node_modules
    del package-lock.json
    npm install
    
  • On macOS/Linux:
    rm -rf node_modules package-lock.json
    npm install
    

Step 5: Test Your Setup

Run your start script again:

npm start

Optional: Improve Development Workflow

Since you have webpack-dev-server installed, you can update your package.json scripts to use it directly for live reloading:

"scripts": {
  "start": "webpack-dev-server --mode development",
  "build": "webpack --mode production"
}

Why Your Previous Fixes Didn't Work

Downgrading Babel without matching the babel-loader version won't resolve the conflict—babel-loader 8.x strictly requires Babel 7's @babel/core instead of Babel 6's babel-core. By aligning all versions correctly, you'll eliminate the module resolution error.


内容的提问来源于stack exchange,提问作者Durga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:16:55