【问题标题】:Webpack run build & watch ERRORWebpack 运行构建并查看错误
【发布时间】:2018-05-05 14:57:19
【问题描述】:

我在 medium 上阅读了story,试图学习如何使用 npm 和 webpack 以及现代 JavaScript。在我安装 webpack 之前,一切都很棒。 我尝试运行此命令npm run buildnpm run watch 这些脚本存在于package.json 文件中,为

{
  "name": "ebdae",
  "version": "1.0.0",
  "description": "nodescription",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack --progress -p",
    "watch": "webpack --progress --watch"
  },
  "repository": {
    "type": "git",
    "url": "ebdae"
  },
  "author": "elhakim",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "webpack": "^3.8.1"
  },
  "dependencies": {}
}

但是这会在命令行No configuration file found and no output filename configured via CLI option. A configuration file could be named 'webpack.config.js' in the current directory.显示这个错误

但配置文件通常存在于.bin文件夹中,并且包含以下代码:

module.exports = {
  entry: '../../assets/js/index.js',
  output: {
    filename: '../../assets/js/bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }
      }
    ]
  }
};

树结构如下:

| .git
| assets
    | js
        | index.js
        | bundle.js
| node_modules
    | .bin
        | ...
        | webpack.config.js
| package-lock.json
| package.json

【问题讨论】:

  • 您好,您没有在脚本中提供任何webpack configuration 文件。应该是这样的"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js"
  • 谢谢 @pravesh-khatri,我更改了输入和输出路径以使其正常工作,我将../../ 替换为./。同样,--display-error-details 救了我的培根。 非常感谢

标签: npm webpack build command watch


【解决方案1】:

您没有在脚本中提供任何 webpack 配置文件。

应该是这样的

"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js"

【讨论】:

  • 也许还有一个额外的-p。在 webpack 5.39.1 这可以工作:"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js"
猜你喜欢
  • 2018-08-06
  • 2017-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
  • 2018-06-29
相关资源
最近更新 更多