Open lukekarrys opened 6 months ago
Doing a bit more digging, I found that this is due to the resolve
package not supporting package.json#exports
. So when resolve.sync
is called it looks up package.json#main
which is the ESM version in my reproduction: https://github.com/testdouble/quibble/blob/1afc5fb31f63f19e32dd26d72818bd8d5bb14a5b/lib/quibble.js#L223
This is arguably a misconfigured package.json
. I modeled the fixture after what axios
is doing in their package.json
since that was the culprit in our tests. So I guess an issue/PR is in order to them as well. (Edit: https://github.com/axios/axios/pull/6348) If the main
pointed to the CJS version this wouldn't be an issue for quibble.
So I don't think this is a bug in quibble since package.json#main
should always be a CJS entry point. Another option would be to use another library like resolve.exports
in addition to or in place of resolve
since that supports exports
the way Node does.
A dependency with
a CJStype: "module"
and conditional exports where thedefault
is ESM and therequire
is CJSexports["."].require
and an ESMmain
will fail with anERR_REQUIRE_ESM
error after any call toquibble()
.This reproduces for me with the latest version of quibble (0.9.2) and the latest version of Node 18 (18.20.1) an 20 (20.12.1).
Reproduction
Save the following bash script as
repro.sh
to an empty directory and run it withbash repro.sh
: