Importing packages with `exports` in `package.json`
pomber opened this issue · 3 comments
mdx-bundler
version: 8.0.1node
version: 16.13.2npm
version: 8.1.2
When the source mdx imports something from node_modules
:
import Ipsum from "lorem/ipsum"
# Hello
<Ipsum />
and the lorem
package.json uses the exports field:
{
"name": "lorem",
"exports": {
"./ipsum": "./dist/whatever.js"
}
}
mdx-bundler throws an error:
error: Could not resolve "lorem/ipsum" (mark it as external to exclude it from the bundle)
I think the problem is the @esbuild-plugins/node-resolve
plugin, which uses the resolve
package, which has this issue: browserify/resolve#222
I'm not very familiar with the esbuild ecosystem, but apparently esbuild already handles the exports field . Maybe it could be possible to reuse esbuild path resolution before throwing?
I'm experiencing the same problem, non-ESM packages resolve fine but when I attempt to import an ESM package which should resolve from exports.default
in its package.json, I get a similar "Could not resolve" error.
I have a fork with failing test: https://github.com/revelt/mdx-bundler/tree/pr/support-esm-packages that's a good start
raised remorses/esbuild-plugins#16