Switched to using two layers of `.default` to workaround a webpack/node bug
Node has added built-in support for dynamic imports with the --experimental-modules option, but it has a small issue with webpack. If you expected the result of import('./yourmodule') to be {default: yourmodule}, the issue causes the actual result to be {default: {default: yourmodule}}. (Note the extra default). I believe this is caused by node attempting to keep
Steps to reproduce buggy behavior:
-
Create files files
src/app.jsandsrc/test.js. -
Inside
src/app.jswrite
// src/app.js
Promise.all([
import('./test')
]).then(([
testmodule,
]) => {
console.log("obj: ", testguy);
});
And inside src/test.js write
// src/test.js
console.log("ok")
const o = {a: "hello"}
export default o;
Now, building this with babel preset stage-1 (from yarn add babel-preset-stage-1), after running you'll find the output is obj: [Module] { default: { default: { a: 'hello' } } }, instead of the expected obj: [Module] default: { a: 'hello' } }.