SyntaxError when running Jest with next/jest and SWC #53565
Unanswered
behnamazimi
asked this question in
Help
Replies: 2 comments 1 reply
-
I had this issue and fixed it by importing React to test files:
This must be done in all test files, therefore you can globally import into the setup file instead:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey guys, an old thread, but I faced a similar issue with a next-intl package that is built for ESM module. Problem
The root causeNext.js's SWC-based transformer somehow doesn't support transpiling ESM packages in node_modules — even with The solution:
Appendix
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hey!
I am encountering a
SyntaxError
when attempting to run Jest tests in my Next.js project. I have utilized SWC for bundling and next/jest to generate Jest configs. The error message is as follows:And here is what
@company/design-system/lib/web/components/Icon/Icon.jsx
looks like:The local package also uses @emotion, and everything works fine when I stop importing @emotion in the design system component,
Icon
in this example.The
@company/design-system
local package is added to thetranspilePackage
option innext.config.js
, so next/jest adds it to thetransformIgnorePatterns
injest.config.js
.here is the jest.config.js:
Expected Behavior
Jest should run the tests without encountering any
SyntaxError
related to import statements.Any insights or help to resolve this issue would be highly appreciated!
Additional information
Everything is functioning smoothly on the Next side. I am able to successfully build the project with SWC without facing any issues.
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions