Skip to content

🐛 BUG: html: bad parser state: originalIM was set twice in dynamic MDX #1076

@TeldridgeLDN

Description

@TeldridgeLDN

What version of @astrojs/compiler are you using?

5.7.13

What package manager are you using?

npm

What operating system are you using?

macOS (Darwin 24.3.0)

Describe the Bug

Okay, here's a draft for the Astro compiler bug report. You can copy and paste this into a new issue on https://astro.build/issues/compiler.

Title: Compiler Panic: html: bad parser state: originalIM was set twice in dynamic MDX route

Body:

Hello Astro Team,

I'm encountering a persistent compiler panic when building or running the dev server for my Astro project. The error seems to originate from the Go-based WASM compiler module and specifically points to dynamic MDX route files.

Astro Version: 5.7.13
Node.js Version: v20.19.0
Operating System: macOS (Darwin 24.3.0)

Relevant Dependencies:

  • @astrojs/mdx: ^4.2.6
  • @astrojs/react: ^4.2.7
  • react: ^19.1.0

Error Message (Dev Server & Build):

The primary panic message is:

panic: html: bad parser state: originalIM was set twice [recovered]
        panic: interface conversion: string is not error: missing method Error

Followed by a Go stack trace pointing to internal compiler functions, often ending with:

created by main.main.Transform.func1.1 in goroutine 6
        ./astro-wasm.go:329 +0x7
exit code: 2

And sometimes accompanied by a Vite/Node error:

[ERROR] [UnknownCompilerError] Cannot read properties of undefined (reading 'exports')
  Hint:
    This is almost always a problem with the Astro compiler, not your code. Please open an issue at https://astro.build/issues/compiler.
  Stack trace:
    at /path/to/my/project/src/pages/notes/[slug].astro

Description:

The issue occurs when Astro attempts to process dynamic routes that render MDX content collections. The error specifically highlights src/pages/notes/[slug].astro in the stack trace, even when this file is simplified to a bare minimum. The project uses content collections for notes and projects.

Troubleshooting Steps Taken:

  1. Validated Astro File Syntax: Ensured all .astro files have correct --- code fence separation.
  2. Clean Install: Deleted node_modules and package-lock.json, then ran npm install. The issue persisted.
  3. Simplified Dynamic Route: Reduced src/pages/notes/[slug].astro to a minimal version (see below). The panic still occurred.
  4. Version Check: Confirmed that astro, @astrojs/mdx, and @astrojs/react are on their latest stable versions.

Code Snippets:

  1. src/pages/notes/[slug].astro (Simplified, still causes panic):

    ---
    import { getCollection, type CollectionEntry } from 'astro:content';
    import BaseLayout from '../../layouts/BaseLayout.astro';
    
    export async function getStaticPaths() {
      const notesEntries = await getCollection('notes');
      return notesEntries.map(entry => ({
        params: { slug: entry.slug },
        props: { entry },
      }));
    }
    
    interface Props {
      entry: CollectionEntry<'notes'>;
    }
    const { entry } = Astro.props;
    const { Content } = await entry.render();
    ---
    <BaseLayout title={entry.data.title}>
      <h1>{entry.data.title}</h1>
      <Content />
    </BaseLayout>
  2. src/content/config.ts:

    // src/content/config.ts
    import { defineCollection, z } from 'astro:content';
    
    const notesCollection = defineCollection({
      type: 'content',
      schema: z.object({
        title: z.string(),
        pubDate: z.string().transform((str) => new Date(str)),
        description: z.string().optional(),
        contentStage: z.enum(["Seedling", "Budding", "Evergreen"]),
        contentType: z.enum(["Long-form Essays", "Notes", "Patterns"]),
        tags: z.array(z.string()).optional(),
      }),
    });
    
    const projectsCollection = defineCollection({
      type: 'content',
      schema: z.object({
        title: z.string(),
        description: z.string(),
        publishDate: z.string().transform((str) => new Date(str)),
        services: z.array(z.string()),
        skills: z.array(z.string()).optional(),
        featured: z.boolean().default(false),
        heroImage: z.string().optional(),
        siteUrl: z.string().url().optional(),
      }),
    });
    
    export const collections = {
      'notes': notesCollection,
      'projects': projectsCollection,
    };
  3. Example MDX file (src/content/notes/example-note.mdx):

    ---
    title: "My Example Note"
    pubDate: "2024-01-15"
    description: "A short description of my example note."
    contentStage: "Budding"
    contentType: "Notes"
    tags: ["example", "astro"]
    ---
    
    # This is the heading of my note
    
    Some content here.

Expected Behavior:
The development server should run and the project should build without compiler panics, correctly rendering MDX content from dynamic routes.

Actual Behavior:
The Astro compiler panics with the "originalIM was set twice" error, preventing the dev server from operating correctly and builds from completing.

I suspect this might be an internal bug in the Astro compiler or its interaction with the MDX processing pipeline. Please let me know if any further information or a more minimal reproduction would be helpful.

Thank you!

Link to Minimal Reproducible Example

https://astro.new

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproIssue needs a reproduction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions