remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.07k stars 10.31k forks source link

[Bug]: React Router v7 is unable to pre-render files that import markdown #12155

Closed amanape closed 2 weeks ago

amanape commented 2 weeks ago

What version of React Router are you using?

v7 prerelease

Steps to Reproduce

  1. Create some .md files in /app/markdown and import them into some components (e.g., through a BlogAPI class)
  2. Set prerender function
    reactRouter({
      ssr: false,
      prerender: () => {
        const blogs = blogAPI.getAllBlogs();
        return blogs.map((blog) => `/blog/${stringToSlug(blog.data.title)}`);
      },
    }),
  3. Build with react-router build
  4. Error!
ERROR: No loader is configured for ".md" files:
    at failureErrorWithLog (/Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:1472:15)
    at /Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:945:25
    at runOnEndCallbacks (/Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:1315:45)
    at buildResponseToResult (/Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:943:7)
    at /Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:970:16
    at responseCallbacks.<computed> (/Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:622:9)
    at handleIncomingPacket (/Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:677:12)
    at Socket.readFromStdout (/Users/.../Desktop/Personal/Other/all-hands-original/node_modules/esbuild/lib/main.js:600:7)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}
error: script "build" exited with code 1

Expected Behavior

I should receive a build folder with the pre-render content for my routes

Actual Behavior

Error is thrown!

brophdawg11 commented 2 weeks ago

I think you probably just need a vite plugin that knows how to handle markdown files? Something like https://www.npmjs.com/package/vite-plugin-markdown