Double `.default` needed if using Node.js v14.1.0 and esm modules
Opened this issue · 4 comments
I'm writing my tests in esm modules.
When I switched from using Node.js v12.14.1 plus the esm package to v14.1.0 and the native esm support I noticed that the import behavior is now strange.
const { default: browserFake } = await import("webextensions-api-fake");
// this does not work (worked in Node.js v12.14.1 plus the esm package)
fakeBrowser = browserFake();
// this works
fakeBrowser = browserFake.default();
Note that Node.js own modules and also your own webextensions-jsdom
package are not affected by this.
The distributed source is built by tsc
from TypeScript, configured as "module": "commonjs"
- maybe that has something to do with it. I'll see if I can investigate that at some point.
Personally I've experience a lot of incompatibilities when trying the native ESM support in Node 13+, then tried esm instead which worked quite well for me at the time.
Btw, does import browserFake from "webextensions-api-fake"
work as expected when Node's ESM is used?
No, import browserFake from "webextensions-api-fake"
has the same problem.
Today I was updating an extension I last published in 2019 and also had this issue with Node 18.13.0. Adding the double default workaround mentioned above restored the expected behavior, but probably is not the intended usage.