You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add backend code in lib/ that uses react-dom/server.
Add corresponding jest test.
Run jest and observe error NEXT_RSC_ERR_SERVER_IMPORT: react-dom/server
Describe the Bug
It seems next/jest from Next.js 13.4.10 mistakenly treats backend code in lib/ as server component and then uses a jest next/swc transform that forbids import from react-dom. But the fact is that the backend code in lib/ has nothing to do with server component (or client component).
jest gives the following error:
x NEXT_RSC_ERR_SERVER_IMPORT: react-dom/server
1 | import { renderToStaticMarkup } from "react-dom/server";
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
at Object.transformSync (node_modules/next/src/build/swc/index.ts:865:25)
at transformSync (node_modules/next/src/build/swc/index.ts:1046:19)
at Object.process (node_modules/next/src/build/swc/jest-transformer.ts:117:25)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:542:31)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:671:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:723:19)
...
No app/ dir feature is being used.
Note that the error only happens on v13.4.10 and reverting back to v13.4.9 dismisses it. Thus it might be caused by one of the following PRs based on the release note of v13.4.10:
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64 Binaries: Node: 18.15.0 npm: 9.5.0 Yarn: 3.5.0 pnpm: N/A Relevant Packages: next: 13.4.10 eslint-config-next: 13.4.10 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Jest (next/jest)
To Reproduce
v13.4.10
lib/
that usesreact-dom/server
.jest
and observe errorNEXT_RSC_ERR_SERVER_IMPORT: react-dom/server
Describe the Bug
It seems
next/jest
from Next.js13.4.10
mistakenly treats backend code inlib/
as server component and then uses a jest next/swc transform that forbids import fromreact-dom
. But the fact is that the backend code inlib/
has nothing to do with server component (or client component).jest
gives the following error:No
app/
dir feature is being used.Note that the error only happens on
v13.4.10
and reverting back tov13.4.9
dismisses it. Thus it might be caused by one of the following PRs based on the release note ofv13.4.10
:Expected Behavior
There shouldn't be any error.
next/jest
shouldn't treat any backend code as server component.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: