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
- Remove deprecation warning for Module Context opts According to @sokra in [this comment](https://github.com/webpack/webpack/issues/3158#issuecomment-686617158), these are not deprecated. — committed to bradfrosty/webpack.js.org by bradfrosty 3 years ago
- docs(configuration): Remove deprecation warning for Module Context opts (#5544) According to @sokra in [this comment](https://github.com/webpack/webpack/issues/3158#issuecomment-686617158), these are... — committed to webpack/webpack.js.org by bradfrosty 3 years ago
- Merge sync 2c9602e (#397) * docs(configuration): add default value for `hot` option (#5376) * build(deps-dev): bump cypress from 8.3.0 to 8.3.1 (#5374) Bumps [cypress](https://github.com/cypres... — committed to line/webpack.kr by dkstyle 3 years ago
- Merge sync 69d5fb0 (#455) * build(deps-dev): bump webpack-dev-server from 4.1.0 to 4.1.1 (#5422) * build(deps-dev): bump tailwindcss from 2.2.9 to 2.2.11 (#5423) Bumps [tailwindcss](https://git... — committed to line/webpack.kr by dkstyle 3 years ago
- Merge sync d6a26f1 (#545) * build(deps-dev): bump eslint-plugin-react from 7.25.1 to 7.25.2 (#5470) Bumps [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) from 7.25.1 to 7.2... — committed to line/webpack.kr by dkstyle 3 years ago
- Merge sync d5e76ca (#567) * build(deps-dev): bump webpack from 5.55.0 to 5.55.1 (#5512) Bumps [webpack](https://github.com/webpack/webpack) from 5.55.0 to 5.55.1. - [Release notes](https://github... — committed to line/webpack.kr by dkstyle 3 years ago
- Merge sync f2b590a (#592) * docs: add chrome-extension-archive-webpack-plugin (#5531) * docs(configuration): update `proxy` example configuration (#5540) * build(deps-dev): bump mini-css-extrac... — committed to line/webpack.kr by dkstyle 2 years ago
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: