繁体   English   中英

错误:无法解析babel-loader ...我的webpack.config代码有什么问题?

[英]Error: Can't resolve babel-loader… What is wrong with my webpack.config code?

在过去的几个小时中,我把头撞在墙上,试图弄清楚我的webpack.config发生了什么。 我什至试图恢复到较早的提交,但仍然遇到相同的问题。 任何想法或建议将不胜感激。 谢谢! 在下面发布我的webpack.config和package.json

webpack.config

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


module.exports = {
  entry: [ '@babel/polyfill', './app/index.js',],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index_bundle.js',
  },
  module: {
    rules: [
      { test: /\.js$/, use: 'babel-loader'},
      { test: /\.css$/, use: [ 'style-loader', 'css-loader']},
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
        template: 'app/index.html'
    })
  ],
  mode: process.env.NODE_ENV === 'production' ? 'production': 'development'
};

----------


 ## package.json

{
  "name": "my-reps",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server",
    "build": "NODE_ENV='production' webpack",
    "firebase-init": "firebase login && firebase init",
    "deploy": "npm run build && firebase deploy"
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/polyfill": "^7.0.0",
    "axios": "^0.18.0",
    "bootstrap": "^4.1.3",
    "classnames": "^2.2.6",
    "firebase-tools": "^4.2.1",
    "jquery": "^3.3.1",
    "lodash.debounce": "^4.0.8",
    "moment": "^2.22.2",
    "prop-types": "^15.6.2",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-places-autocomplete": "^7.2.0",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-twitter-embed": "^1.1.3",
    "react-twitter-widgets": "^1.7.1",
    "reactstrap": "^6.5.0"
  },
  "devDependencies": {
    "@babel/core": "^7.1.6",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/plugin-transform-react-constant-elements": "^7.0.0",
    "@babel/preset-env": "^7.1.6",
    "@babel/preset-react": "^7.0.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-loader": "^8.0.0",
    "babel-register": "^6.26.0",
    "css-loader": "^1.0.0",
    "html-webpack-plugin": "^3.2.0",
    "style-loader": "^0.22.1",
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5"
  }
}

错误信息:

ERROR in ./node_modules/lodash/lodash.js
Module not found: Error: Can't resolve 'babel-loader' in '/Users/michaelberry/Desktop/my-reps'
 @ ./node_modules/lodash/lodash.js 1:0-41
 @ ./node_modules/html-webpack-plugin/lib/loader.js!./app/index.html

ERROR in ./node_modules/lodash/lodash.js
Module not found: Error: Can't resolve 'babel-loader' in '/Users/michaelberry/Desktop/my-reps'
 @ ./node_modules/lodash/lodash.js 1:0-41
 @ ./node_modules/html-webpack-plugin/lib/loader.js!./app/index.html

「wdm」:编译失败。

您最近是否偶然更新了npm软件包? 特别是devDependencies中的以下软件包:

  • 的WebPack
  • 的WebPack-CLI
  • 巴别塔
  • 巴贝尔装载机

这些软件包的某些版本在构建时可能会引起问题。

如果是这样,您可以尝试将devDependencies重新安装到以前使用的版本。

另一种方法是使用最新版本。 有时npm update命令由于某种原因将不会安装最新版本。 因此,您需要访问npm网站并检查每个devDependencies的最新版本。

暂无
暂无

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

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