Search code examples
ecmascript-6webpackes6-module-loader

Webpack 2.0 checking existence of tree shaken ES6 module imports


In Webpack 2.0 (@2.1.0-beta6), if I go to import a file that points to a file that doesn't exist, I get a build time error.

//x.js
import { foo } from './y'

//y.js
export function foo () { return 5 }

If I go to import an export that doesn't exist from a file that exists, I get a runtime error.

//x.js
import { baz } from './y'

//y.js
export function foo () { return 5 }

Is there a way to have Webpack check exports in the same way it resolves files?

//webpack.config.js
module.exports = {
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015-native-modules']
        }
    ],
  }
}

Solution

  • As of webpack@2.1-beta15, warnings have now been added for imports of ES6 exports.