Hello all,
I’ve been encountering an issue with my site, where markdown files that render perfectly during local development are failing to show up in production on Netlify. Instead of rendering the content, I see what looks like HTML being output as plain text. I’ve tried several approaches to fix the issue, but nothing has worked so far.
Project Setup
Link to project branch: [WIP] Website Migration by jamesmwu · Pull Request #463 · uclaacm/hack.uclaacm.com · GitHub
Link to project deploy: https://deploy-preview-463--acm-hack.netlify.app/blog
- Tech Stack:
- Vite
- React
react-markdown
for rendering markdown- Deployment to Netlify
- Site: A blog section where the posts are written in markdown and served dynamically.
- Node Version: I recently upgraded to
20.17.0
as there were issues with using Node v16, and I resolved the node versioning problems, but the main issue persists.
Problem
Locally, running vite build
and then serving with vite preview
works as expected, and all markdown content is rendered properly in the blog posts. However, once deployed to Netlify, the markdown is replaced with what looks like HTML being displayed as raw text. You can see this if you click any of the blog posts in the link to the project deploy above.
Here’s what I’ve tried so far:
Things We’ve Tried
- File Paths & Vite’s
import.meta.url
- I moved the markdown files into the
public/
folder to ensure Vite can serve them properly. - Updated
blogs.js
to use the following format:
js
Copy code
markdown: new URL('/blogPosts/fall2023/hey-future-interns/index.md', import.meta.url).href,
- This was done to ensure proper referencing of static assets. But the issue persisted after multiple builds.
- Clearing Netlify Cache & Redeploying
- I cleared the Netlify build cache several times and redeployed. This didn’t resolve the issue.
- Adjusted Build Command & Node Version
- I set the correct
build.command
innetlify.toml
tovite build
. - Updated the Node.js version in Netlify settings to
20.17.0
, ensuring the proper environment was used during the build process. The node version problem was resolved, but the markdown issue persists.
- Netlify Logs (No Errors)
- The Netlify build logs show a successful build with no errors, and the static assets are deployed correctly. There are no 404s or issues with file fetching that I can see. However, the markdown content still doesn’t display as expected.
- Production URL Issue
- The blog posts show raw HTML code in the browser rather than parsed markdown. Locally, everything works fine with both
npm run build
andnpm run preview
. In fact, even if I donetlify build
andnetlify serve
, the deploy looks fine locally.
- No Network Errors
- I’ve also checked the network tab in DevTools for the production site, and there are no issues with fetching the markdown files.
Build Environment
- Vite Version: 5.4.8
- Netlify Build Command:
vite build
- Publish Directory:
dist/
What I’m Looking For
I’ve gone through the Netlify docs and several community posts, but I can’t seem to find anything that resolves this issue. Has anyone experienced a similar problem with markdown rendering via Vite on Netlify? Are there any other configuration changes I should try?
Would appreciate any advice or insights into what might be going wrong or further debugging steps.
Thank you!