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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 Bug: Mocha (10.x) and Chai (5.x) don't work together #5073
Comments
they do work together, chai has just moved to shipping pure ESM which means CJS consumers must now use dynamic import or a bundler. the error will be from trying to import chai into a commonjs module you can instead do a dynamic import, |
In my case all my test modules are ESM already, but still the same error. Besides, the error is about "unknown .ts extension" of the test/spec file itself, which means that the execution didn't even enter the test module yet. In that case, I don't think the way chai being imported in the test module makes a difference. But again, I'm doing |
@MuTsunTsai Is your TypeScript configured to compile your imports to ESM or CommonJS? Often projects write ESM imports in TypeScript only to have it compile it to CommonJS |
you are right that the error isn't necessarily about trying to import CJS i suspect it is from using ts-node with mocha, and having |
I'm using mocha & chai in a pure ESM project, before and after upgrading chai to 5.x. The problem appears to come from how Mocha is including Chai. Chai declares itself as ESM and Mocha is trying to PS I think the comment within Mocha's |
here's an example which works: https://gist.github.com/43081j/78ce1392abb5043b02a29355006880a5 if you don't use ts-node (like me), you can just build the typescript and run the resulting JS the same way. mocha 10 does work with chai 5, and with most (or all) other ESM packages |
I've pointed out a different solution in this discussion: |
Per chaijs/chai#1575, Mocha does work with Chai 5.x. It's just up to users to configure the ESM shenanigans correctly. Filed mochajs/mocha-examples#77 to track adding in an example to our examples repo. Thanks for the discussion all! 馃 |
Bug Report Checklist
faq
label, but none matched my issue.Expected
mocha --recursive
to work.Actual
Minimal, Reproducible Example
described in this issue:
GuyKh/10bis.Slackbot#1021
Versions
Mocha - 10.2.0
Chai - 5.0.0
Additional Info
As described in this issue in Chai repo - it seems that Chai 5.x is ESM (=Module).
Settings examples are there.
The text was updated successfully, but these errors were encountered: