Resolving module import error for sanity-plugin-markdown in Next.js
This is a classic TypeScript module resolution issue. Based on the official sanity-plugin-markdown GitHub repository, here's how to fix your error:
1. First, verify the installation
Make sure you've installed both required packages:
npm install sanity-plugin-markdown easymde@2Note that easymde@2 is a required peer dependency that must be installed alongside the plugin.
2. Clear your cache and reinstall
Sometimes npm installations can be incomplete:
rm -rf node_modules package-lock.json
npm install3. Restart your TypeScript server
If you're using VS Code:
- Press
Cmd/Ctrl + Shift + P - Type "TypeScript: Restart TS Server"
- Select it
This often resolves module resolution issues where TypeScript is caching old state.
4. Check your import statement
In your sanity.config.ts, make sure you're importing correctly:
import { markdownSchema } from 'sanity-plugin-markdown'
export default defineConfig({
// ... other config
plugins: [markdownSchema()],
})5. Special case for Next.js (pages directory)
If you're using Next.js without the app directory (using the pages directory), you need to use a different import path because Next.js doesn't support CSS imports from node_modules:
import { markdownSchema } from 'sanity-plugin-markdown/next'Then add this to the top of pages/_app.tsx:
import 'easymde/dist/easymde.min.css'6. Verify your Node.js version
Since you're on Next.js 15, ensure you're running Node.js 20 or higher. You can check with:
node --version7. Check your package.json
After installation, verify both packages appear in your package.json:
{
"dependencies": {
"sanity-plugin-markdown": "^6.0.0",
"easymde": "^2.x.x"
}
}The most common causes are either an incomplete installation or the TypeScript server needing a restart. Try these steps in order and the error should resolve! If you're still having issues after trying all of these, double-check that your tsconfig.json has proper module resolution settings (though this is usually fine by default).
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.