sagard
sagard

Reputation: 13

output.filename is required

System

macOS Sierra, node v5.6.0, webpack v 2.2.1 - Was working fine in Webpack 1.8.0

Work

Converting JS to TS

Current behavior

This is the error message

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)

This is my config file. There's no typo in filename or anywhere that I can see

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'
      }
    }
  }
}

If you try to use uglifyJS like so - it says "TypeError: Cannot read property 'unshift' of undefined"

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;

Upvotes: 1

Views: 6439

Answers (2)

Akshay Vijay Jain
Akshay Vijay Jain

Reputation: 15935

I got this error, when I had by mistake two instances of module.exports in the webpack.config.js file, removing extra module.exports object fixed the issue

Also this issue comes in case you misspell correct(module.exports) to wrong(module.export)

Upvotes: 0

Michael Jungo
Michael Jungo

Reputation: 32972

You didn't define output.filename but module.output.filename which doesn't exist. Same goes for plugins and resolve they should not be under module but at the top level. You need to close the curly brace for module after the rules array.

Another problem is that you try to set enforce: "pre" on a loader, but that is meant to go on a rule. So you need to have two rules for .ts, one rule that has enforce: "pre" for the tslint-loader and the other one with just the ts-loader.

Your config should be like this:

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'
    }
  }
}

Upvotes: 2

Related Questions