Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Webpack Dev Middleware Should Support export default #1378

Closed
RehanSaeed opened this issue Nov 8, 2017 · 2 comments
Closed

Webpack Dev Middleware Should Support export default #1378

RehanSaeed opened this issue Nov 8, 2017 · 2 comments

Comments

@RehanSaeed
Copy link

RehanSaeed commented Nov 8, 2017

I have extended one of your templates and added the following NPM scripts so that I can write my Webpack configuration using TypeScript which has a number of advantages:

"build:webpackconfig": "tsc --lib es6 webpack.config.vendor.ts && tsc --lib es6 webpack.config.ts",
"build": "npm run build:webpackconfig && webpack --config webpack.config.vendor.js && webpack",
"build:prod": "npm run build:webpackconfig && webpack --config webpack.config.vendor.js --env.prod && webpack --env.prod"

This totally works and Webpack is happy with my JavaScript file generated from TypeScript however the WebpackDevMiddleware fails to run with the error:

One or more errors occurred. (TypeError: Cannot read property 'publicPath' of undefined

My TypeScript looks like this:

import * as path from "path";
import * as webpack from "webpack";
import { IArguments, INewConfiguration, INewConfigurationBuilder } from "./webpack.common";

const configurationBuilder: INewConfigurationBuilder = 
  (env: IArguments): INewConfiguration => {
    const configuration: INewConfiguration = {
      // ...
    };
    return configuration;
  };
export default configurationBuilder;

This outputs the following JavaScript:

"use strict";
exports.__esModule = true;
var path = require("path");
var webpack = require("webpack");

var configurationBuilder = function (env) {
  var configuration = {
    // ...
  };
  return configuration;
};
exports["default"] = configurationBuilder;

The key difference is the last line of code. I've experimented with changing it and the WebpackDevMiddleware only works when it is module.exports = configurationBuilder;. To generate that line in TypeScript I have to use export = configurationBuilder; which is invalid TypeScript because the default tsconfig.json file has module set to es2015.

The key point is that Webpack supports exports["default"] = configurationBuilder;, so the WebpackDevMiddleware should too.

@SteveSandersonMS
Copy link
Member

Thanks. Fixed.

@RehanSaeed
Copy link
Author

Will this fix be released in the 2.1 update?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants