standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

repl/cjs vs mjs script import differences #825

Closed jsg2021 closed 5 years ago

jsg2021 commented 5 years ago

I just updated a module in my project and it started failing. It went from cjs, to cjs-pretending-to-be-esm with Object.definePropetry(module, { __esModule: {value: true }})… however, using this test script in the repl (node -r esm) and pasting this in results in the correct behavior…

import queue from 'p-queue'; // @ v6.0.2
console.log(queue);

however, if you put that in a file and node -r esm test.mjs it outputs the “incorrect” thing. Additionally, if you rename the test to test.js it results in the correct thing. 😕

jsg2021 commented 5 years ago

This was probably a dumb question. I think the issue is that p-queue should expose a module entry point. Its currently compiled TypeScript which outputs webpack/babel-like fake-esm/cjs modules.

jdalton commented 5 years ago

Hi @jsg2021!

The esm loader locks down .mjs files (they get no extra esm options support).