【问题标题】:I did npm run build and got a lot of ERRORS我做了 npm run build 并得到了很多错误
【发布时间】:2021-09-17 07:12:52
【问题描述】:

我遇到了很多错误,不知道从哪里开始。

错误信息

> webpack

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[1] should be one of these:
   ["..." | object { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }, ...]
   -> A rule.
   Details:
    * configuration.module.rules[1].loader should be a non-empty string.
      -> A loader request.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! react_drill@1.0.0 build: `webpack`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the react_drill@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yamaguchishuuhei/.npm/_logs/2021-08-28T17_30_34_922Z-debug.log

package.json

{
  "name": "react_drill",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "webpack"
  },
  "repository": {
    "type": "git",
   omitted

webpack.config.js

module.exports = {
    entry: {
      app: "./src/index.js"
    },
    output: {
      path: __dirname + '/public/js',
      filename: "[name].js"
    },
      devServer: {
      contentBase: __dirname + '/public',
      port: 8080,
      publicPath: '/js/'
    },
    devtool: "eval-source-map",
    mode: 'development',
    module: {
      rules: [{
        test: /\.js$/,
        enforce: "pre",
        exclude: /node_modules/,
        loader: "eslint-loader"
      }, {
        test: /\.css$/,
        loader: ["style-loader","css-loader"]
      }, {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
       }]
    }
  };

【问题讨论】:

  • 错误是提供所有信息。 module.rules[1].loader 不应为空字符串。你给了一个数组。也许看看Rules.use
  • 也许一开始你需要const path = require('path'); 之前module.exports

标签: javascript npm webpack


【解决方案1】:

你的webpack.config.js格式错误,rule.loader不支持传入数组,试试use这样

module.exports = {
    entry: {
      app: "./src/index.js"
    },
    output: {
      path: __dirname + '/public/js',
      filename: "[name].js"
    },
      devServer: {
      contentBase: __dirname + '/public',
      port: 8080,
      publicPath: '/js/'
    },
    devtool: "eval-source-map",
    mode: 'development',
    module: {
      rules: [{
        test: /\.js$/,
        enforce: "pre",
        exclude: /node_modules/,
        loader: "eslint-loader"
      }, {
        test: /\.css$/,
        use: ["style-loader","css-loader"]
      }, {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
       }]
    }
  };

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 2020-02-17
    • 1970-01-01
    • 2015-06-06
    • 2022-01-06
    • 2021-03-03
    • 1970-01-01
    • 2018-01-21
    • 2022-08-17
    相关资源
    最近更新 更多