next.js: Error should not be imported outside of pages/_document and experimental-edge

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.16.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.8
      eslint-config-next: 13.4.8
      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)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/rbox-risk/testedge

To Reproduce

When using: -pages directory and -custom _document and switching to the experimental edge rendering runtime using the value exported from the page export const runtime = "experimental-edge"

results in the error [Error: <Html> should not be imported outside of pages/_document. Read more: https://nextjs.org/docs/messages/no-document-import-in-page]

image

reverting to next@13.4.7 disappears the error

Describe the Bug

Bug appears to be related to experimental edge rendering runtime

Expected Behavior

minimal page example should render either nodejs or edge depending upon the rendering runtime.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 9
  • Comments: 23 (4 by maintainers)

Most upvoted comments

I’m getting the same error with next@13.5.2 but when I revert back to 3.4.19 it works fine.

Look at this issues, setting NODE_ENV=production explicitly fixes this issues for me

Also having this issue on v14.1.0 when I don’t set NODE_ENV to production when building

In my case I was getting this error with next@14.0.1 while using bun, when I switched from bun to npm it started working again.

I can confirm that NODE_ENV=production does the fix. node 18.19.1 next@14.1.1 Alpine Linux v3.19

This error just started happening for me after upgrading from next@14.0.3 to next@14.0.4. Only on Vercel. Adding NODE_ENV=production to the build step doesn’t help. I am also NOT using “experimental-edge”

Rolling back to Next 14.0.3 works.

I can confirm that NODE_ENV=production does the fix. node 18.19.1 next@14.1.1 Alpine Linux v3.19

ITS WORK. on Ubuntu: export NODE_ENV=production then rebuild and start

I am also getting the same error. with export const runtime = "experimental-edge";

Update: on older version of next.js it’s working fine. "next": "13.3.0",