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

Using --turbo with next-mdx-remote/rsc throws ModuleBuildError #63318

Closed
devjiwonchoi opened this issue Mar 15, 2024 · 17 comments
Closed

Using --turbo with next-mdx-remote/rsc throws ModuleBuildError #63318

devjiwonchoi opened this issue Mar 15, 2024 · 17 comments
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.

Comments

@devjiwonchoi
Copy link
Member

devjiwonchoi commented Mar 15, 2024

Link to the code that reproduces this issue

https://github.com/devjiwonchoi/repro-next-turbo-mdx-remote-rsc

To Reproduce

  1. pnpm i
  2. pnpm dev
  3. Open http://localhost:3000

Current vs. Expected behavior

Current

Package next-mdx-remote (serverComponentsExtenalPackages or default list) can't be external
The request next-mdx-remote/rsc matches serverComponentsExtenalPackages (or the default list), but it can't be external:
The package seems invalid. require() resolves to a EcmaScript module, which would result in an error in Node.js.

Expected

It should not throw

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:32:11 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 11
Binaries:
  Node: 18.17.0
  npm: 9.6.7
  Yarn: 1.22.19
  pnpm: 8.15.4
Relevant Packages:
  next: 14.2.0-canary.23 // Latest available version is detected (14.2.0-canary.23).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.2
Next.js Config:
  output: N/A

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

Turbopack (--turbo)

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

next dev (local)

Additional context

This issue has been introduced at next@14.1.1-canary.64
Related PR: #62235

This works when using webpack only (next dev)

PACK-2927

@devjiwonchoi devjiwonchoi added the bug Issue was opened via the bug report template. label Mar 15, 2024
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Mar 15, 2024
@devjiwonchoi
Copy link
Member Author

Update: I published remote-mdx, a fork of next-mdx-remote, and resolved the output.

IMHO this is still a bug since webpack can handle this package.

@ctjlewis
Copy link
Contributor

ctjlewis commented Mar 23, 2024

Thank you @devjiwonchoi. Actually using your workaround in the meantime. cc @leerob @jaredpalmer

@FairyPenguin
Copy link

Any updates on this,

Same issue with - "next": "14.2.0-canary.56",

@FairyPenguin
Copy link

FairyPenguin commented Apr 4, 2024

Update: I published remote-mdx, a fork of next-mdx-remote, and resolved the output.

IMHO this is still a bug since webpack can handle this package.

Thanks @devjiwonchoi worked for me on "14.2.0-canary.56"

@padmaia padmaia added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Apr 9, 2024
@Pilaton
Copy link

Pilaton commented Apr 12, 2024

@devjiwonchoi remote-mdx displays an error.

Error: Cannot access Image.propTypes on the server. 
You cannot dot into a client module from a server component. 
You can only pass the imported name through.

@devjiwonchoi
Copy link
Member Author

devjiwonchoi commented Apr 13, 2024

@Pilaton
Copy link

Pilaton commented Apr 13, 2024

@devjiwonchoi What exactly is this topic supposed to help me with?
remote-mdx gives an error when passing an 'Image' component to it.

const components = { Image };

<MDXRemote components={components} source={mdx} />

I haven't had time yet to see if the problem is in remote-mdx or next 14.2

@bcigdemoglu
Copy link

I get the following error with remote-mdx:

Unhandled Runtime Error
TypeError: Cannot read properties of null (reading 'useState')

Call Stack
f.exports.r.useState
node_modules/.pnpm/remote-mdx@0.0.4_react@18.2.0/node_modules/remote-mdx/dist/index.js (1:31840)
S
node_modules/.pnpm/remote-mdx@0.0.4_react@18.2.0/node_modules/remote-mdx/dist/index.js (1:56687)

@timneutkens
Copy link
Member

@bcigdemoglu can you open a new issue with a reproduction as you're mentioning another library it seems.

@devjiwonchoi
Copy link
Member Author

grzegorzpokorski added a commit to grzegorzpokorski/next-shop that referenced this issue Apr 21, 2024
Using --turbo with next-mdx-remote/rsc throws ModuleBuildError; vercel/next.js#63318
@devjiwonchoi
Copy link
Member Author

@bcigdemoglu did some update on it, could you try the latest version?

@devjiwonchoi
Copy link
Member Author

@Pilaton the error seems to be with mishandling client / server component, not on nextjs or remote-mdx

Open issue w repro to remote-mdx repo, I'll be glad to take a look!

@dcodesdev
Copy link

Using next@14.2.3 same issue

@leerob
Copy link
Member

leerob commented Apr 26, 2024

const nextConfig = {
  transpilePackages: ['next-mdx-remote'],
}

export default nextConfig;

^ Temporary workaround, duplicate issue here (#64525) which is being worked on (open PR #64918).

@leerob leerob closed this as completed Apr 26, 2024
@devjiwonchoi
Copy link
Member Author

devjiwonchoi commented Apr 26, 2024

@leerob @ForsakenHarmony I may be wrong but since the package I published remote-mdx is also a Native ESM package, the reason for the error may be different.

The error message I received is from the code below when the file is ESM, but the syntax is not ESM.

(FileType::EcmaScriptModule, false) => {
// even with require() this resolves to a ESM,
// which would break node.js, bundle it
unable_to_externalize(
request_str,
"The package seems invalid. require() resolves to a EcmaScript module, which \
would result in an error in Node.js.",
)

Therefore, I suspected having CommonJS syntax on the ESM module (.js file).

Where the output of next-mdx-remote's ./dist/rsc.js should be ESM syntax but has CJS syntax in it, resulting an error I believe.

Tried to fix it but unfortunately I'm not a Rustacean yet... 😅

@papadavis47
Copy link

I ran into this issue when upgrading packages today for my blog . The workaround mentioned by @leerob did the trick for me.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

10 participants