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

index.mjs imports invalid module #1450

Open
arv opened this issue Feb 1, 2022 · 6 comments
Open

index.mjs imports invalid module #1450

arv opened this issue Feb 1, 2022 · 6 comments

Comments

@arv
Copy link

arv commented Feb 1, 2022

The file index.mjs is trying to import index.js. index.js has no exports so you get a SyntaxError.

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.

@keithamus
Copy link
Member

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...

@RebeccaStevens
Copy link

@keithamus I don't think it's possible to support both without using a build tool.
I could submit a PR to add rollup and get it to output for each of the different environments if you like.

@43081j
Copy link
Contributor

43081j commented Jan 19, 2023

@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:

var util = require('./chai/utils');

it then imports addProperty here:

exports.addProperty = require('./addProperty');

which then imports chai here:

var chai = require('../../chai');

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.

@keithamus
Copy link
Member

keithamus commented Jan 19, 2023

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.

@43081j
Copy link
Contributor

43081j commented Jan 19, 2023

makes sense.

from a quick look, i can see the whole use(...) concept will make it difficult - allowing patching of the exported module by third party packages basically.

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 😂

@43081j
Copy link
Contributor

43081j commented Jan 20, 2023

@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.

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

4 participants