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

Importing default from next/document in ESM inside a third-party package doesn't work #64796

Open
DiegoAndai opened this issue Apr 19, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.

Comments

@DiegoAndai
Copy link

DiegoAndai commented Apr 19, 2024

Link to the code that reproduces this issue

https://github.com/DiegoAndai/esm-test-8-next-document-monorepo?tab=readme-ov-file

To Reproduce

Follow instructions in: https://github.com/DiegoAndai/esm-test-8-next-document-monorepo?tab=readme-ov-file#running-the-repro

Current vs. Expected behavior

Current

When importing next/document.js from an ESM module, the default value is not properly set:

import Document from "next/document.js";

Document.getInitialProps; // unexpectedly undefined
Document.default.getInitialProps; // function

Expected

In ESM, the default import should be set with using the syntax:

import Document from "next/document.js";

Document.getInitialProps; // function

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 16
Binaries:
  Node: 18.19.0
  npm: 10.4.0
  Yarn: 1.22.21
  pnpm: 8.14.1
Relevant Packages:
  next: 14.2.2 // Latest available version is detected (14.2.2).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

Issue found when trying to add exports field to the material-nextjs integration package.

@DiegoAndai DiegoAndai added the bug Issue was opened via the bug report template. label Apr 19, 2024
@github-actions github-actions bot added the Pages Router Related to Pages Router. label Apr 19, 2024
@DiegoAndai DiegoAndai changed the title Importing default from next/document in ESM doesn't work Importing default from next/document in ESM inside a third-party package doesn't work Apr 19, 2024
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. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

1 participant