-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
[Jest 28][Yup Resolver] SyntaxError: Cannot use import statement outside a module #396
Comments
This issue probably should belong to Jest as we didn't make any change to the module. |
I truly understand that. But it will be nice if you can give any help 🙏 |
Can you provide a repo or a codesandbox please? |
I got this error too for Zod resolver after updating to Jest 28.
|
Hey guys, I found a workaround for now as described in this comment. First I create a new file called module.exports = (path, options) => {
// Call the defaultResolver, so we leverage its cache, error handling, etc.
return options.defaultResolver(path, {
...options,
// Use packageFilter to process parsed `package.json` before
// the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
packageFilter: pkg => {
// jest-environment-jsdom 28+ tries to use browser exports instead of default exports,
// but @hookform/resolvers only offers an ESM browser export and not a CommonJS one. Jest does not yet
// support ESM modules natively, so this causes a Jest error related to trying to parse
// "export" syntax.
//
// This workaround prevents Jest from considering @hookform/resolvers module-based exports at all;
// it falls back to CommonJS+node "main" property.
if (pkg.name === '@hookform/resolvers') {
delete pkg['exports'];
delete pkg['module'];
}
return pkg;
},
});
}; Then in my resolver: '<rootDir>/.jest/resolver.js', Hope it helps you guys. |
@georgekaran thank you so much! It worked for me! |
It's also possible to manually import from the correct dist file e.g. |
@nico1510 I've tried that, but didn't worked. |
I usually get circular dependencies when I do that. |
Is there an update on this? |
Adding the offending modules (in my case "vest" and "@hookform/resolvers") to Eg. |
🎉 This issue has been resolved in version 2.9.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I faced this problem, this is my workaround
Then create file
Modify your
Then update import
to
|
I'm receiving a Syntax Error when running my tests with Jest v28. It was working with v27.x
I'm using React 17 and Next 12 with TypeScript.
Here's my deps list:
And here is my jest config file:
Environment
The text was updated successfully, but these errors were encountered: