Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite Struggles with Exports #65

Open
shellscape opened this issue Nov 13, 2023 · 2 comments
Open

Vite Struggles with Exports #65

shellscape opened this issue Nov 13, 2023 · 2 comments

Comments

@shellscape
Copy link

Any chance of getting an ESM version or some default export shimming introduced? vite dev dislikes the package immensely, throwing an error which resembles:

Uncaught SyntaxError: The requested module '/@fs/private/tmp/jsx-email-starter/node_modules/.pnpm/extend@3.0.2/node_modules/extend/index.js?v=ae42d2d7' does not provide an export named 'default' (at index.js?v=ae42d2d7:350:8)

unified is making use of this package (and is ironically ESM-only) and running vite with anything that wants to use unified is quite impossible without extensive gymnastics.

@justmoon
Copy link
Owner

This has come up before, see #57.

After playing around with adding ESM support, the issue is that this module currently supports very old Node.js versions which obviously don't support ESM at all. Adding a transpiler or maintaining two copies of the code and tests adds a lot of complexity.

To add ESM support for this module, the best way imo would be to make a new major version which fully switches to ESM and drops support for Node.js versions <12. Kind of like what @sindresorhus has done with his packages. Users of older Node.js versions could continue to use the older version of the package.

I'd be fine with that but @ljharb has been the primary maintainer for this package, so he'd have to agree.

@ljharb
Copy link
Collaborator

ljharb commented Nov 13, 2023

Have you filed an issue on vite? It should be able to handle all existing CJS packages, or else it's broken.

As for ESM-only packages, if you look at adoption numbers for basically all of them, without exception, the vast majority remains permanently stuck on the last CJS version - iow, it's objectively proven to be a failed initiative.

We could certainly ship a .mjs file and the exports field - VERY carefully, so as to not make it a breaking change - that would re-export all the properties on the CJS module.exports as named ESM exports, but that simply shouldn't be necessary. node itself uses cjs-module-lexer to figure out things like this for its native ESM implementation, so vite certainly should be able to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants