-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
index.mjs imports invalid module #1450
Comments
Thanks for the issue @arv. PRs are welcome. There have been multiple attempts but it seems really difficult to satisfy all bundlers and tools. I think we might need to just refactor to use ES modules and release a breaking change which drops support for anything that doesn't use ES modules... |
@keithamus I don't think it's possible to support both without using a build tool. |
@keithamus just ran into this myself, there's also a problem preventing us from transforming chai at build time to CJS: circular imports. chai imports its utils here: Line 25 in 3a8c49a
it then imports Line 94 in 3a8c49a
which then imports chai here: chai/lib/chai/utils/addProperty.js Line 7 in 3a8c49a
this isn't valid in ESM. so even if we use a build process to convert chai into an ES module (e.g. rollup's commonjs plugin), it will fail at run time thanks to this impossible circular import. time has also moved on a lot by now. im pretty confident we could just move chai to use ES modules in the source and have a build process produce a commonjs version. we'd have to ship both versions in the npm package (increased package size) but it means it'd be a pure ES module and still a CJS module. |
Thanks @43081j. I agree. Moving to es modules would be a good move. Annoyingly there's a lot of work involved, but I think that's the priority for Chai 5. I have been incredibly short on time lately though, due to a variety of other commitments, as have the rest of the chai maintainers. |
makes sense. from a quick look, i can see the whole won't be as straight forward when the module doesn't exist as a variable. that would probably be better off being reworked so it doesn't mutate the module itself but keeps track somewhere of extensions. in other words, i can see why its a big job now 😂 |
@keithamus something like #1498 maybe (based in 5.x.x branch fwiw) good if some day you and/or the other maintainers get chance to have a stab at that, or help finish off this one if its along the right lines. |
The file
index.mjs
is trying to importindex.js
.index.js
has no exports so you get aSyntaxError
.Any chance of publishing a valid ES module version of chai? There are of course alternatives like using @esm-bundle/chai or skypack but it would be nice if the source of truth was using ES modules.
The text was updated successfully, but these errors were encountered: