-
-
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
Error: Cannot find module '/xxxxxxx/node_modules/chai/register-should' #1455
Comments
I'm having the same issue Another workaround would be: - import 'chai/register-should'
+ import { should } from 'chai'
+ should() |
We ran into the same problem with We found a workaround: add The issue seems to be that an |
I get this issue when running the following CLI command: npx mocha --no-deprecation --require chai/register-expect --require ts-node/register "src/**/*.ts"
Ideally, in my case, I'm including chai expect by default on all TS files, so I don't have an easy way to do the workaround identified above by re-writing my imports |
Experiencing the same problem on Both However, using Using
does work. |
As a workaround for globally registering // mocha.setup.mjs
import { expect } from 'chai';
global.expect = expect; mocha -r ./mocha.setup.mjs … |
all of the above are wrongly using the extensionless import, it seems most or all of you will resolve your issues by using the exact path: this works: import 'chai/register-should.js'; similarly, this works: mocha --require chai/register-should.js some-test.js in both 5.x and 4.x these work |
good catch, we should update that 👍 fwiw, if we had |
I can send a PR tonight |
if you don't mind, that would be much appreciated 🙏 feel free to ping me for review |
I just tried including the ERROR: /[…]/node_modules/chai/register-expect.js:1
import {expect} from './index.js';
^^^^^^
SyntaxError: The requested module './index.js' does not provide an export named 'expect' There is a series/daisy-chain of barrel files, which make debugging this rather difficult (and probably has unintended consequences like causing all modules to get evaluated, regardless of whether they're used). I think you would be much better off using packageJson.exports like so: {
"exports": {
"./": "./chai.js",
"./package.json": "./package.json",
"./register-assert": "…",
// …
}
} PS sorry for the delay—I had the wrong laptop with me last night. |
if we introduce an exports map, it will still be of the JS files most likely rather than aliases. could you possibly make a reproduction in a repo somewhere, or a gist? just so i can see the setup as a whole would help me understand as i'm not seeing the same behaviour |
Oh! Sorry i missed your response. Looks like it's been handled though. |
Hi :)
I'm facing as is the title issue.
Env & Phenomenon
I confirmed this problem happened in chai
4.2.0
,4.6.3
and Node.js12.x
,14.x
,16.x
. I do not check other chai and node.js versions.I'm using chai with mocha and I specified
chai/register-should
inmocha.rc.yml
.Also this problem occur with
mocha spec.js -r chai/register-should
command.Error log
Others
This issue seems fixed in 5276af6. Because, I specify the commit in
package.json
like below this problem is solved.But, it commit reverted in 022c2fa. So, how to solve it?
Thank you :)
The text was updated successfully, but these errors were encountered: