This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
Unable to require.resolve a package location when the package is 'type:module' and 'exports' is defined without exposing package.json
.
#547
Labels
duplicate
This issue or pull request already exists
First, see this popular question on StackOverflow, whose solution is now broken for some packages using Node ESM (with
"type": "module"
and an"exports"
field that does not explicitly exposepackage.json
).The problem is that if a package has the following in
package.json
,Then one can not use
require()
orrequire.resolve()
to resolve package locations like the can with normal CommonJS packages.For example, trying to run
require.resolve('@scope/package/package.json')
will fail withIn the repl you'll see a
MODULE_NOT_FOUND
message.The package author would need to expose
package.json
for resolving to work:I thought that
exports
was supposed to affect onlyimport
statements, but notrequire
.The text was updated successfully, but these errors were encountered: