create-react-app: Missing export should be a compile error
This is only relevant in master which uses Webpack 2.
If I change src/index.js
from
import App from './App';
to
import {App} from './App';
I’m getting:
The screen is blank (because of the runtime error).
Notice how the real problem is at the very bottom (missing export), yet it looks like the first two are the important ones.
The terminal output is also very restrained (because it is a warning):
I wonder what are the reasons for this. I think a missing ES6 export should totally be a compile error because it is so easy to mess it up, and then have weird runtime errors as a result.
I have two questions:
- Why isn’t in an error by default?
- Can we make this an error in CRA setup?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 12
- Comments: 15 (12 by maintainers)
Some typescript constructs emit incorrect import/exports (related to the loader impl, not sure if it’s fixed now). So we used a warning. But I guess it fine to add an option upgrading it to an error.
After further investigation after what @insin, it seems
strictModuleExceptionHandling
isn’t what we want (despite some various sources I found). It looks like we need to add a custom hook to parse the webpack warnings.Maybe @sokra could give us some more insight?
It looks like this config triggers generation of
try
/catch
wrappers when calling the generated module function at runtime, but doesn’t upgrade missing modules to an error at build time.Seems like we need to set
strictModuleExceptionHandling
totrue
. It was added but never documented, and that’s why we missed it.