webpack: Webpack fails silently when named import doesn't exist

I’m submitting a feature request Webpack version: 2.1.0-beta.21

Please tell us about your environment: Linux

Current behavior: When I try to import a named import, it fails silently if the name import does not exist. I wish webpack would fail loudly when it cannot find the import at build time

For example:

// file1.js
const var1 = 'var1'
export { var1 }

and

// file2.js
import { var2 } from './file1'
// at this point, var2 is undefined at runtime because it was never exported from file1.js

Desired behavior: Instead, I want it to fail at build time. Is there a webpack option or some other technique I can use to catch this error sooner?

  • What is the motivation / use case for changing the behavior? This will catch typos at build time, and prevent a lot of headaches caused by undefined imports.
  • Browser: [all ]
  • Language: [ES6/7]

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Bumping into this as well, babel-preset-env’s modules: false doesn’t fix it in my case.

https://github.com/webpack/webpack/issues/6339

I simplified my entry point and my config a lot, and figured out that the warning is generated by webpack if I disable babel-loader. With babel-loader enabled for .js files, the warnings are suppressed or swallowed somehow. I’m currently searching the babel-loader repo for answers on that.

Update: specifically the issue appears to be with babel-preset-env which transpiles ES6 modules and doesn’t appear to warn about missing imports. I set my .babelrc to disable module transpilation in babel, and let webpack do that for me. Like so:

{
  "presets": [
      ["env", {
          "modules": false
      }],
      "react"
  ]
}