开发者问题收集

Webpack 初始化失败

2018-06-18
2425

我刚刚按照在线教程开始使用 Webpack。

每当我运行 npm run dev 时,Web Pack 都不会运行并显示错误: Webpack 已使用与 API 架构不匹配的配置对象进行了初始化。

- configuration.output 具有未知属性“fileName”。这些属性有效: 对象 {auxiliaryComment?, chunkFilename?, webassemblyModuleFilename?, globalObject?, crossOriginLoading?, jsonpScriptType?, chunkLoadTimeout?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTemplate?, devtoolNamespace?, filename?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, chunkCallbackName?, library?, libraryTarget?, libraryExport?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine? } ->影响编译输出的选项。 output options 告诉 webpack 如何将编译后的文件写入磁盘。

这是我的文件:

package.json

{
  "name": "forkify",
  "version": "1.0.0",
  "description": "Forkify Project",
  "main": "index.js",
  "scripts": {
    "dev": "webpack"
  },
  "author": "Sanjay",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.12.0",
    "webpack-cli": "^3.0.8"
  },
  "dependencies": {}
}

webpack.config.js

const path = require('path');

module.exports = {
    entry: './src/js/index.js',
    output: {
        path: path.resolve(__dirname, 'dist/js'),
        fileName: 'bundle.js'
    },
    mode: 'development'
}
1个回答

您的输出对象错误。(fileName => filename)

const path = require('path');

module.exports = {
    entry: './src/js/index.js',
    output: {
        path: path.resolve(__dirname, 'dist/js'),
        filename: 'bundle.js'
    },
    mode: 'development'
}
Idan Hen
2018-06-18