antfu/vite-plugin-md

Issue with module name resolution when used in an esm package

lgollut opened this issue · 3 comments

When used in a type="module" package, the resolutions of some dependencies seems to be broken by the fact that there is no automatic resolution of file extensions. Using node --experimental-specifier-resolution=node resolve this issue, but the flag is experimental and is not safe to use as per https://nodejs.org/api/esm.html#customizing-esm-specifier-resolution-algorithm.

I've created a reproduction repo here https://github.com/lgollut/vite-plugin-md-es-resolution

image

I tried your repo and the package which was causing me errors is fp.ts which is the premier functional library for Typescript. It does export both ESM and CJS as you see above but I know for resolution there are sometimes issues when one of the exports doesn't use .cjs or .mjs.

I'd like to help with this but I'd need your help with at least a suggestion on how to help ViteJS better navigate a 3rd party library. This doesn't directly have anything to do with this repo though so I'm going to close this for now.

If you have any suggestions on how we can make consumers who want to build to esm I will try to be helpful as this is clearly the future but for this plugin in particular is typically used in a node environment where the esm push has been historically a little less pronounced.

One thing I'd suggest is maybe add an issue (or ideally a PR) to the fp-ts repo to get them to start transpiling the ESM build to .mjs

@lgolllut I have configured the bundler to include the fp-ts code directly into this repo's distribution. This is available as of v0.17.0 ... have a look and see if this works for you. Seems to work from a very limited test but I feel I haven't really put it through all the tests yet.