output.filename是必需的

时间:2017-03-07 14:58:12

标签: webpack webpack-2

系统

macOS Sierra,node v5.6.0,webpack v 2.2.1 - 在Webpack 1.8.0中运行良好

工作

将JS转换为TS

当前行为

这是错误消息

Error: 'output.filename' is required, either in config file or as --output-filename
at processOptions (/Users/sagardubey/workspace/ts-sdk/node_modules/webpack/bin/convert-argv.js:488:11)
at processConfiguredOptions (/Users/sagardubey/workspace/ts-sdk/node_modules/webpack/bin/convert-argv.js:141:4)
at module.exports (/Users/sagardubey/workspace/ts-sdk/node_modules/webpack/bin/convert-argv.js:117:10)
at Object. (/Users/sagardubey/workspace/ts-sdk/node_modules/webpack/bin/webpack.js:153:40)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:140:18)

这是我的配置文件。文件名中没有拼写错误或我可以看到的任何地方

var webpack = require("webpack");
var path = require('path')
module.exports = {
  devServer: {
  },
  devtool: 'source-map',
  entry: {
    "ym.min": "./src/bootstrap.ts",
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          {
            loader: "ts-loader"
          },
          {
            loader: "tslint-loader",
            enforce: "pre"
          }
        ]
      }
    ],
    output: {
      filename: '[name].js',
      path: './dist'
    },
    plugins: [],
    resolve: {
      modules: [
        "node_modules",
        path.join(__dirname, 'node_modules')
      ],
      extensions: [".webpack.js", ".web.js", ".ts", ".js", "*"],
      enforceExtension: false,
      alias: {
        'handlebars': 'handlebars/runtime.js'
      }
    }
  }
}

如果你试图像这样使用uglifyJS - 它说" TypeError:无法读取属性' unshift'未定义"

var config = require('./webpack.config');
    var webpack = require('webpack');

    config.plugins.unshift(new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      },
      output: {
        comments: false,
      },
    }));

    module.exports = config;

2 个答案:

答案 0 :(得分:2)

您没有定义output.filename,但module.output.filename并不存在。同样适用于pluginsresolve,它们不应位于module之下,而应位于顶层。您需要在module数组后关闭rules的大括号。

另一个问题是你尝试在加载器上设置enforce: "pre",但这意味着要遵守规则。因此,您需要为.ts制定两条规则,一条规则enforce: "pre"tslint-loader,另一条规则仅为ts-loader

您的配置应该是这样的:

var webpack = require("webpack");
var path = require('path')
module.exports = {
  devServer: {
  },
  devtool: 'source-map',
  entry: {
    "ym.min": "./src/bootstrap.ts",
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        enforce: "pre",
        use: [
          {
            loader: "tslint-loader"
          }
        ]
      },
      {
        test: /\.ts$/,
        use: [
          {
            loader: "ts-loader"
          }
        ]
      }
    ]
  }, // End of module
  output: {
    filename: '[name].js',
    path: './dist'
  },
  plugins: [],
  resolve: {
    modules: [
      "node_modules",
      path.join(__dirname, 'node_modules')
    ],
    extensions: [".webpack.js", ".web.js", ".ts", ".js", "*"],
    enforceExtension: false,
    alias: {
      'handlebars': 'handlebars/runtime.js'
    }
  }
}

答案 1 :(得分:0)

我收到此错误,当我错误地在webpack.config.js文件中有两个module.exports实例时,删除了额外的module.exports对象修复了问题

此问题也出现在您错误拼写正确(module.exports)为错误的情况下(module.export)