Skip to content
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

(Next.js v13.4.10) NEXT_RSC_ERR_SERVER_IMPORT: react-dom/server #52757

Open
1 task done
jonioni opened this issue Jul 16, 2023 · 0 comments
Open
1 task done

(Next.js v13.4.10) NEXT_RSC_ERR_SERVER_IMPORT: react-dom/server #52757

jonioni opened this issue Jul 16, 2023 · 0 comments
Labels
bug Issue was opened via the bug report template. Testing Related to testing with Next.js.

Comments

@jonioni
Copy link

jonioni commented Jul 16, 2023

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

  1. Install Next.js v13.4.10
  2. Follow the standard jest setup: Setting up Jest (with the Rust Compiler)
  3. Add backend code in lib/ that uses react-dom/server.
  4. Add corresponding jest test.
  5. 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:

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

@jonioni jonioni added the bug Issue was opened via the bug report template. label Jul 16, 2023
@github-actions github-actions bot added the Testing Related to testing with Next.js. label Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Testing Related to testing with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant