Implementing markdown editor in Sanity blog starter throwing error

7 replies
Last updated: Jan 25, 2021
Hi! I'm trying to implement the markdown editor in the default blog starter! Tried the plugin but it's throwing error!
AI Update

It sounds like you're running into CSS import issues when trying to use the markdown plugin with the Sanity blog starter! This is a known issue with the plugin, especially when embedding Sanity Studio in Next.js applications.

The error you're seeing (Global CSS cannot be imported from within node_modules) is a documented issue that affects the plugin when used with Next.js. Here's what's happening and how to fix it:

The Problem

The sanity-plugin-markdown plugin tries to import CSS from within node_modules, which Next.js doesn't allow by default. This affects both older versions (with react-mde) and the current v3 version (which uses @uiw/react-md-editor).

Solutions

Option 1: Use the latest version (if you haven't already) Make sure you're using the latest version of the plugin:

npm install sanity-plugin-markdown@latest

The v3 version switched from react-mde to @uiw/react-md-editor, but some CSS import issues may still exist.

Option 2: Workaround for embedded Studio If you're embedding the Studio in Next.js (which seems likely given the blog starter context), one user found success by:

  1. Copying the plugin code into your project (similar to how the Sanity blog template handles custom plugins)
  2. Moving the CSS import to your _app.js or _app.tsx
  3. Using dynamic imports for any components with browser-only dependencies:
const MarkdownEditor = dynamic(() => import('./your-markdown-component'), {
  ssr: false,
  loading: () => <div>Loading...</div>,
});

Option 3: Consider alternatives If the markdown plugin continues to give you trouble, you might want to consider:

  • Using Sanity's built-in Portable Text with markdown shortcuts enabled
  • Using a simple text field with markdown formatting handled on the frontend
  • Waiting for the plugin maintainers to resolve the CSS bundling issues

Known Limitations

Be aware that the current v3 version of the plugin has also dropped drag-and-drop image upload support, so you'll need to manually add image URLs if you need images in your markdown.

If you share more details about your specific setup (Studio version, how you're embedding it, etc.), I can provide more targeted guidance!

Show original thread
7 replies
Hi Subha! What error are you seeing?
Hi Subha! What error are you seeing?
Could you try running
npm install
before trying once more? And if that still doesn't work, could you verify that the plugin shows up in both your
package.json
file and your
sanity.json
file?
Do you see the plugin listed in your studio folder's
package.json
and
sanity.json
files?
If you cloned the entire starter repo (i.e. didn't create this from sanity.io/create ), you'll want to ensure to install the plugin in the
/template/studio
folder, not in the monorepo root. Could you try if installing it in your studio root folder adds the plugin to the files mentioned above?
Np! You might want to re-create the starter from sanity.io/create to avoid any confusion by our starter template setup - especially when it comes to deploying to production later. Do feel free to continue this way if you prefer though. We'll be here to clarify anything if needed πŸ™‚
Hi Subha, the markdown plugin takes care of markdown on the studio side, but not on the front-end side. You could try using this component for example: https://github.com/remarkjs/react-markdown πŸ™‚

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?