Closed karlhorky closed 1 year ago
Ley's migrate up
is however still failing, so having a different error message is not as much a real problem as it is confusing...
Ideally what I would love would be to have ley.config.js
+ all .js
imports treated as ESM, even without "type": "module"
in package.json
(or maybe ley.config.ts
supported, when tsm
is used - which would also unlock ESM syntax)
But yeah, can also see downsides here...
You can't do this for Node reasons, not ley. You can only (technically) have ESM within .js
with "type":"module"
in your pkg config. Thats how native loaders can know what to expect/allow. (Bundlers can be different story.. aka more permissive.) This was done because ESM was a later, additive feature, and .js
had to remain IIFE/CommonJS-oriented by default... type: module
turns on the ESM assumption.
The reason you're seeing ERR_REQUIRE_ESM
is because import()
is tried first, and falls back to require
. Node is throwing an error (with a stderr warning, see CSB) and so the require()
tried again, also throwing an error.
Ok good, so it sounds like this is "by design" and Ley won't go in the direction of bundler behavior? If so, we can probably close this issue and leave it as being documented.
It's just plain Node loading / ESM semantics. I don't think it needs documenting since it applies to every module (and .js
file) within the ecosystem. There isn't anything ley specific about the situation.
thanks~!
Hi @lukeed 👋 hope things are going well!
Encountered an unusual problem the other day:
"type": "module"
inpackage.json
)ley.config.mjs
file which imports a.js
file, which also uses ESMERR_REQUIRE_ESM
error, trying torequire()
theley.config.mjs
file 🤔CodeSandbox: https://codesandbox.io/p/sandbox/lucid-babycat-74sz59?file=%2Fley.config.mjs%3A3%2C19
I guess I would instead expect the error that Node.js throws here, complaining that A) it cannot find the named export and B) that
ley-import-broken.js
is a CommonJS module:Somewhat related to this other issue by @mplibunao: