找不到模块:错误:无法解析“ C:\ Users \ durgat \ reactApp”中的模块“ babel-loader”

时间:2019-01-30 11:00:32

标签: reactjs

{
  "name": "reactApp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack --mode development",
    "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "webpack": "^4.29.0",
    "webpack-cli": "^3.2.1",
    "webpack-dev-server": "^3.1.14"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "html-webpack-plugin": "^3.2.0"
  }
}

请帮助我解决此问题,在进行许多更改(例如)后,我仍然遇到此问题,我将babel降到了最低版本,并使用此命令安装了npm,并且我进行了许多更改,但没有结果。 还有 webpack.config.js文件

 const path = require('path');
  const HtmlWebpackPlugin = require('html-webpack-plugin');

    module.exports = {
           entry: './main.js',
           output: {
           path: path.join(__dirname, '/bundle'),
           filename: 'index_bundle.js'
             },
            devServer: {
            inline: true,
            port: 8080
             },
            module: {
                rules: [
                      {
                           test: /\.jsx?$/,
                           exclude: /node_modules/,
                           loader: 'babel-loader',
                           query: {
                           presets: ['es2015', 'react']
                                 }
                       }
                      ]
                    },
           plugins:[
                 new HtmlWebpackPlugin({
                 template: './index.html'
             })
          ]
   }

1 个答案:

答案 0 :(得分:0)

我认为这可能会有所帮助,因为我不知道什么是webpack文件配置
但是您可以在您的webpack文件中尝试一下

resolveLoader: {
  root: path.join(__dirname, 'node_modules')
}

请共享您的webpack.config文件