import {
foobar1,
foobar2,
foobor3, //typo! this key doesn't exist in the module.
} from './module_file.js'
console.log(foobar1, foobar2, foobar3) //EXPLODES
One of the most frequent silly mistakes I make when using the new ES6 style import statement is that I'll have a typo in one of the keys in object destructuring. I can't think of a single instance where I'd ever want a value in a destructuring assignment to be undefined
. Is there any way to force the import statement to fail-fast if one of the items I'm trying to import is undefined?
ie:
import {
doesntExistInModule //EXPLODE NOW! π₯π₯π₯
} from './module_file.js'
- There is no hook allowing a module to run some code before its dependencies load. This means that modules have no control over how
their dependencies are loaded.- There is no error recovery for import errors. An app may have hundreds of modules in it, and if anything fails to load or link, nothing runs. You canβt import in a try/catch block. (The upside here is that because the system is so static, webpack can detect those errors for you at compile time.)
For more details, read it out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With