question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mdx-bundler doesn't work in NextJS' getServerSideProps when deployed on Vercel: The package "esbuild-linux-64" could not be found, and is needed by esbuild.

See original GitHub issue
  • mdx-bundler version: 7.0.0
  • node version: v14.15.4
  • npm version: 7.24.0

Relevant code or config

Just copy pasted from the mdx-bundler github example:

import { bundleMDX } from "mdx-bundler";
import * as React from "react";
import { getMDXComponent } from "mdx-bundler/client";

export default function Home({ code, frontmatter }) {
  // it's generally a good idea to memoize this function call to
  // avoid re-creating the component every render.
  const Component = React.useMemo(() => getMDXComponent(code), [code]);
  return (
    <>
      <header>
        <h1>{frontmatter.title}</h1>
        <p>{frontmatter.description}</p>
      </header>
      <main>
        <Component />
      </main>
    </>
  );
}

export const getServerSideProps = async () => {
  const mdxSource = `
---
title: Example Post
published: "2021-02-13"
description: This is some description
---

# Wahoo

import Demo from './demo'

Here's a **neat** demo:

<Demo />
`.trim();

  const result = await bundleMDX(mdxSource, {
    files: {
      "./demo.tsx": `
import * as React from 'react'

function Demo() {
  return <div>Neat demo!</div>
}

export default Demo
    `,
    },
  });

  const { code, frontmatter } = result;

  return { props: { code, frontmatter } };
};

What you did:

I’m trying to use mdx-bundler server side in NextJS’ getServerSideProps. Everything works fine when I keep things static (with getStaticProps), but I get a 500 error when I try to access the same page using getServerSideProps. All works on my machine (both in dev & when built), but not on Vercel.

What happened:

2021-11-12T10:39:25.261Z 57ade67b-7c54-4c70-bf8a-70c038937a29 ERROR Error: The package “esbuild-linux-64” could not be found, and is needed by esbuild. If you are installing esbuild with npm, make sure that you don’t specify the “–no-optional” flag. The “optionalDependencies” package.json feature is used by esbuild to install the correct binary executable for your current platform. at generateBinPath (/var/task/node_modules/esbuild/lib/main.js:1643:15) at esbuildCommandAndArgs (/var/task/node_modules/esbuild/lib/main.js:1699:11) at ensureServiceIsRunning (/var/task/node_modules/esbuild/lib/main.js:1856:25) at Object.build (/var/task/node_modules/esbuild/lib/main.js:1749:26) at bundleMDX (/var/task/node_modules/mdx-bundler/dist/index.js:215:33) at async mdx2 (/var/task/packages/site/.next/server/pages/api/mdx2.js:93:18) at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils.js:102:9) at async Server.handleApiRequest (/var/task/node_modules/next/dist/server/next-server.js:1014:9) at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:901:37) at async Router.execute (/var/task/node_modules/next/dist/server/router.js:210:32)

Reproduction repository:

https://github.com/dominik-sfl/next-mdx-bundler Demo here: https://next-mdx-bundler.vercel.app/

Problem description:

mdx-bundler works in Next.JS on Vercel with getStaticProps, but not with getServerSideProps. Everything fine on my local machine.

Suggested solution:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
dominik-sflcommented, Nov 13, 2021

@AnthonyKuang Yes, exactly. Downgrading esbuild seems to work for me though. Downgraded to 0.12.09 and it’s working again.

0reactions
jonhiltcommented, Jan 26, 2022

I must confess to not really knowing what “NFT” is, but I’m guessing this may be relevant?

https://github.com/vercel/nft/pull/262

(I’m also running into the same issue, found that pull request and related issues whilst searching for a solution 😃)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vercel: ERROR Error: The package "esbuild-linux-64" could ...
I am working on a simple NextJs application where I want to have multiple subdomains in it. I am deploying the application on...
Read more >
could not resolve "fs" | The AI Search Engine You Control
Your quick fix is to take react scripts down to v4 until a fix for v5 is in place unless you are comfortable...
Read more >
bun-cli-linux-x64 - npm Package Health Analysis | Snyk
We found a way for you to contribute to the project! Looks like bun-cli-linux-x64 is missing a security policy. You can connect your...
Read more >
The New Stack Context: Serverless Web Content Delivery with ...
Vercel CEO Guillermo Rauch discusses JAMstack-based service that allows developers to simply push their code to git to update their web site or...
Read more >
Next.js - Full Context Review
What I'm not going to do: is introducing how to work with Next.js from the ground up. Instead, I will analyse the core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found