Skip to content

Bug Report: Import Alias Issue with Contentlayer in Next.js + Turbopack #74

@mageshyt

Description

@mageshyt

After upgrading to the latest version of Next.js and enabling Turbopack, I am facing an import alias issue related to Contentlayer. The error occurs when trying to import contentlayer/generated inside a page component.

Error Message

Module not found: Can't resolve 'contentlayer/generated'

Full error:

Image

Steps to Reproduce

  1. Upgrade to the latest Next.js version with Turbopack enabled.
  2. Use @/.contentlayer/generated in an import statement.
  3. Run next dev or next build.
  4. Encounter the import alias resolution issue.

Expected Behavior
The alias @/.contentlayer/generated should resolve correctly without errors.

Current Workaround (Not Working)
I attempted to fix this by modifying my next.config.js as follows:

turbo: {
  root: "./",
  resolveAlias: {
    "contentlayer/generated": "./.contentlayer/generated",
  },
  resolveExtensions: [".mdx", ".tsx", ".ts", ".jsx", ".js", ".json"],
}

Despite this, the issue persists.

Configuration Details

  • tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./*"],
      "contentlayer/generated": ["./.contentlayer/generated"]
    }
  },
  "include": [".contentlayer/generated"]
}
  • next.config.js
import { withContentlayer } from "next-contentlayer";
const nextConfig = {
  experimental: {
    turbo: {
      resolveAlias: {
        "contentlayer/generated": "./.contentlayer/generated",
      }
    }
  }
};
export default withContentlayer(nextConfig);

System Info

  • Next.js Version: 15.2.4
  • Node.js Version: 21.4.0
  • Operating System:mac os

Additional Context

  • The issue seems to be related to Turbopack's module resolution.
  • It works fine with Webpack, but breaks with Turbopack.
  • contentlayer is properly generated inside .contentlayer/generated.

Would appreciate any guidance on fixing this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions