【问题标题】:webpack file webpack.config.js [Failed to load]webpack 文件 webpack.config.js [加载失败]
【发布时间】:2021-04-08 18:09:47
【问题描述】:

我在使用 webpack cli 时遇到了这个问题

我正在尝试运行这个文件 webpack:

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

module.exports = {
    entry: './src/app.js',
    output: {
        path: path.resolve(__dirname , '..dist'),
        filename: 'bundle.js'
    },
    plugins = [
        new HtmlWebPackPlugin({
            template: './src/index.hbs'
        })
    ]
}

sistem 的文件如下:

  • webpack-工作流
    • node_modules
      • 部分
      • 静态
      • 样式
      • app.js
      • index.js
    • package-lock.json
    • packege.json
    • webpack.config.js

这是我的 package.son:

{
  "name": "webpack-workflow",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "autoprefixer": "^10.2.5",
    "css-loader": "^5.2.0",
    "file-loader": "^6.2.0",
    "handlebars": "^4.7.7",
    "handlebars-loader": "^1.7.1",
    "html-webpack-plugin": "^5.3.1",
    "image-webpack-loader": "^7.0.1",
    "mini-css-extract-plugin": "^1.4.1",
    "node-sass": "^5.0.0",
    "postcss-loader": "^5.2.0",
    "rimraf": "^3.0.2",
    "sass-loader": "^11.0.1",
    "webpack": "^5.31.0",
    "webpack-cli": "^4.6.0",
    "webpack-dev-server": "^3.11.2"
  }
}

所以我从终端输入:npx webpack --config webpack.config.js

显示此错误

[webpack-cli] Failed to load 'C:\Users\Gerso\Documents\WebPack\webpack-workflow\webpack.config.js' config
[webpack-cli] Error: Cannot find module 'C:\Users\Gerso\Documents\WebPack\webpack-workflow\webpack.config.js'
Require stack:
- C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\bootstrap.js
- C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\bin\cli.js
- C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack\bin\webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)       
    at loadConfig (C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\webpack-cli.js:1322:31)
    at C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\webpack-cli.js:1409:74
    at Array.map (<anonymous>)
    at WebpackCLI.resolveConfig (C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\webpack-cli.js:140    at WebpackCLI.createCompiler (C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\webpack-cli.js:1839:33)
    at WebpackCLI.buildCommand (C:\Users\Gerso\Documents\WebPack\webpack-workflow\node_modules\webpack-cli\lib\webpack-cli.js:1954:31) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Gerso\\Documents\\WebPack\\webpack-workflow\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
    'C:\\Users\\Gerso\\Documents\\WebPack\\webpack-workflow\\node_modules\\webpack-cli\\lib\\bootstrap.js',
    'C:\\Users\\Gerso\\Documents\\WebPack\\webpack-workflow\\node_modules\\webpack-cli\\bin\\cli.js',
    'C:\\Users\\Gerso\\Documents\\WebPack\\webpack-workflow\\node_modules\\webpack\\bin\\webpack.js'
  ]
}
PS C:\Users\Gerso\Documents\WebPack\webpack-workflow> npx webpack --config webpack.config.js
[webpack-cli] Failed to load 'C:\Users\Gerso\Documents\WebPack\webpack-workflow\webpack.config.js' config
[webpack-cli] C:\Users\Gerso\Documents\WebPack\webpack-workflow\webpack.config.js:10
    plugins = [
    ^^^^^^^^^^^

我做错了什么??

【问题讨论】:

    标签: webpack webpack-dev-server webpack-4


    【解决方案1】:

    在你的webpack.config.js

    plugins = [

    应该是

    plugins: [

    要验证您的配置,您可以运行:

    webpack configtest webpack.config.js
    

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2018-11-26
      • 2017-01-16
      • 2018-12-20
      • 1970-01-01
      相关资源
      最近更新 更多