Search code examples
reactjstypescriptnext.jsmdx

NextJS MDX doesn't produce for build for production


Context

So I'm working on a NextJS v15, app router website. I just installed the @next/mdx and other packages are specified on the official nextjs md support docs.

Problem

The nextjs is not building the application. That is, the bun run build command is exiting without any error, but isn't building a production application.

Errors:

Here's the log:

While building:

$ bun run build                                                                                                                                                                    

$ next build
   ▲ Next.js 15.1.2
   - Environments: .env.local

   Creating an optimized production build ...
(node:15530) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies

While running the production server:

$ bun start                                                                                                                                                                        

$ next start
   ▲ Next.js 15.1.2
   - Local:        http://localhost:3000
   - Network:      http://10.255.255.254:3000

 ✓ Starting...
[Error: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id]
error: script "start" exited with code 1

What all have I tried

  • I have tried removing all dependencies, cleaning all the cache and reinstalling again using bun install.
  • Doing the exact same using npm
  • Changing NextJS version to 14.2.21

How you can reproduce

Just create a next app using app router, and then install the dependencies given here

Other information

Dependencies:

    "dependencies": {
        "@hookform/resolvers": "^3.9.1",
        "@icons-pack/react-simple-icons": "^10.2.0",
        "@mdx-js/loader": "^3.1.0",
        "@mdx-js/react": "^3.1.0",
        "@next/mdx": "^15.1.2",
        "@radix-ui/react-accordion": "^1.2.2",
        "@radix-ui/react-dialog": "^1.1.4",
        "@radix-ui/react-icons": "^1.3.2",
        "@radix-ui/react-label": "^2.1.1",
        "@radix-ui/react-slot": "^1.1.1",
        "@types/mdx": "^2.0.13",
        "class-variance-authority": "^0.7.1",
        "clsx": "^2.1.1",
        "embla-carousel-autoplay": "^8.5.1",
        "embla-carousel-react": "^8.5.1",
        "husky": "^9.1.7",
        "lint-staged": "^15.2.11",
        "lucide-react": "^0.469.0",
        "next": "^15.1.2",
        "next-themes": "^0.4.4",
        "react": "19.0.0",
        "react-countup": "^6.5.3",
        "react-dom": "19.0.0",
        "react-hook-form": "^7.54.2",
        "sharp": "^0.33.5",
        "sonner": "^1.7.1",
        "tailwind-merge": "^2.6.0",
        "tailwindcss-animate": "^1.0.7",
        "wemakedevs": ".",
        "zod": "^3.24.1"
    }

NextJS Config

# next.config.mjs

import createMDX from "@next/mdx";

/** @type {import('next').NextConfig} */
const nextConfig = {
    // Configure `pageExtensions` to include markdown and MDX files
    pageExtensions: ["js", "jsx", "md", "mdx", "ts", "tsx"],
    // Optionally, add any other Next.js config below
};

const withMDX = createMDX({
    // Add markdown plugins here, as desired
});

// Merge MDX config with Next.js config
export default withMDX(nextConfig);

Solution

  • I tried getting down to a minimal reproduction of the issue.

    As it turns out, simple next.js site does build in my system, but as soon as I install the dependency and put in the config recommended by nextjs docs, it stops building.

    I tried doing the same on a different system and it does work there. I started checking what are all the different components, and as it turns out, the node on my new system was v23.5.0 and that on my old system was v23.1.0. As soon as I upgrade, it started working fine.