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

Dev server not working when using @next/mdx with plugins and --turbo #71819

Closed
carloscuesta opened this issue Oct 24, 2024 · 14 comments · Fixed by #72802
Closed

Dev server not working when using @next/mdx with plugins and --turbo #71819

carloscuesta opened this issue Oct 24, 2024 · 14 comments · Fixed by #72802
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. Markdown (MDX) Related to Markdown with Next.js. Turbopack Related to Turbopack with Next.js.

Comments

@carloscuesta
Copy link

carloscuesta commented Oct 24, 2024

Link to the code that reproduces this issue

https://github.com/carloscuesta/next-mdx-turbo-plugins-issue

To Reproduce

  1. Clone the provided repository
  2. Install the dependencies
  3. Run the development server

Current vs. Expected behavior

I'm expecting that the dev server starts normally however the process ends with the following error:

Error: loader /Users/carloscuesta/Downloads/next-mdx-turbo-issue/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_/node_modules/@next/mdx/mdx-rs-loader.js for match "*.mdx" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.

The error doesn't happen when I remove the plugin that I'm passing into the withMDX function:

❌ Error: pnpm run dev --turbopack

export default withMDX({
  options: {
    remarkPlugins: [remarkGfm]
  }
})(nextConfig);

✅ No error: pnpm run dev --turbopack

export default withMDX({
  options: { remarkPlugins: [] }
})(nextConfig);

✅ No error: pnpm run dev (without turbo flag)

export default withMDX({
  options: { remarkPlugins: [remarkGfm] }
})(nextConfig);

error

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.14.0
  npm: 10.7.0
  Yarn: N/A
  pnpm: 9.12.2
Relevant Packages:
  next: 15.0.1 // Latest available version is detected (15.0.1).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

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

Markdown (MDX), Turbopack

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

next dev (local)

Additional context

No response

@carloscuesta carloscuesta added the bug Issue was opened via the bug report template. label Oct 24, 2024
@github-actions github-actions bot added Markdown (MDX) Related to Markdown with Next.js. Turbopack Related to Turbopack with Next.js. labels Oct 24, 2024
@kylemh
Copy link
Contributor

kylemh commented Oct 24, 2024

Also replicable via https://tailwindui.com/templates/spotlight

  • Install deps
  • Use codemod to upgrade to Next 15 (with or without React 19)
  • Run dev server
  • See same error as OP

@JayamalHettiarachchi
Copy link

JayamalHettiarachchi commented Oct 25, 2024

I'm having the same issue with Next 15.0.1

@nimaa77
Copy link

nimaa77 commented Oct 25, 2024

passing remarkPlugins or rehypePlugins to createMDX breaks the dev server (with turbo)

const withMDX = createMDX({
  options: {
    remarkPlugins: [remarkGfm],
    rehypePlugins: [rehypeSlug],
  },
});

@jxnnyo
Copy link

jxnnyo commented Oct 26, 2024

Experiencing same issues as OP.

const withMDX = createMDX({
  // Add markdown plugins here, as desired
  options: {
    remarkPlugins: [remarkGfm],
    rehypePlugins: [],
  },
});

var nextConfig = withAxiom(withMDX(config));

Error: loader C:\Users\---\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]_\node_modules\@mdx-js\loader\index.cjs for match "*.mdx" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.

@wesbos
Copy link
Contributor

wesbos commented Oct 27, 2024

Also hitting this. Works fine without --turbo

Removing rehype plugins allows it to run

@github-actions github-actions bot added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Oct 28, 2024
@dzienisz

This comment has been minimized.

@keegandonley
Copy link

Chiming in that I have this same issue on version 15.0.2, with the same reproductions as others

@timneutkens
Copy link
Member

timneutkens commented Nov 7, 2024

MDX plugins are JavaScript functions which can't be transferred into Turbopack (given it's not JS), we'll have to add something like mdx.config.js to the MDX loader (and that flows into @next/mdx) so that these plugins don't have to be passed around like they are currently.

For now you can remove --turbopack to have it run. The issue has already been triaged, you don't have to post comments saying "it still happens", that's expected when the issue is open 🙂

@dzienisz

This comment has been minimized.

@karlhorky
Copy link
Contributor

karlhorky commented Nov 7, 2024

This has now been documented in the Next.js docs - in the remark and rehype plugins section:

@karlhorky
Copy link
Contributor

karlhorky commented Nov 18, 2024

@timneutkens thanks for the implementation of MDX plugins in Turbopack (remark, rehype, recma plugins)!

I see it was released in [email protected]

I opened a new PR documenting the new capabilities of using plugins via the string name config over here:

ijjk pushed a commit that referenced this issue Nov 18, 2024
Followup to #72241 and
#72467

Documenting the new Turbopack support for MDX plugins (remark, rehype,
recma plugins):

- #71819 (comment)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

Clarify that MDX-related plugins (remark and rehype plugins) are
supported when options are serializable, by using the new string name
config format

### Why?

Support was added in 72802

- #72802

### How?

Add a new section about using plugins with Turbopack
@bdrtsky
Copy link

bdrtsky commented Nov 23, 2024

So what's the solution? Why it's closed? I can't use plugins with --turbopack, so I have to remove it. Because this makes MDX unusable in Next.js.

@karlhorky
Copy link
Contributor

@bdrtsky I think maybe you missed reading my comment above fully?

It's now possible to use remark/rehype/recma plugins with Turbopack.

My PR linked above added documentation for that, at the "Using Plugins with Turbopack" docs section here:

@carloscuesta
Copy link
Author

@bdrtsky It's not released yet outside of canary, so you'll have to wait or use the canary version to use remark/rehype plugins with --turbo.

wyattjoh pushed a commit that referenced this issue Nov 28, 2024
Implements support for passing MDX related plugins as strings instead of
as JS functions, this makes sure you can use MDX plugins with Turbopack.

This still means that e.g. the options have to be serializable, in
testing a few plugins these plugins usually have serializable options
though.

Fixes #71819
Fixes PACK-3345

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
wyattjoh pushed a commit that referenced this issue Nov 28, 2024
Followup to #72241 and
#72467

Documenting the new Turbopack support for MDX plugins (remark, rehype,
recma plugins):

- #71819 (comment)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

Clarify that MDX-related plugins (remark and rehype plugins) are
supported when options are serializable, by using the new string name
config format

### Why?

Support was added in 72802

- #72802

### How?

Add a new section about using plugins with Turbopack
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. linear: turbopack Confirmed issue that is tracked by the Turbopack team. Markdown (MDX) Related to Markdown with Next.js. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.