Module parse error with @sanity/orderable-document-list plugin import
This error typically happens when you're using the @sanity/orderable-document-list plugin in a Next.js project (or similar framework) that isn't configured to properly transpile the Sanity UI package. The error message about "sourceType: module" indicates that webpack is encountering ES modules but doesn't know how to handle them.
The most common fix is to add the Sanity packages to your Next.js transpilation configuration. In your next.config.js (or next.config.mjs), add the transpilePackages option:
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@sanity/ui', '@sanity/orderable-document-list']
}
module.exports = nextConfigIf you're using next.config.mjs:
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@sanity/ui', '@sanity/orderable-document-list']
}
export default nextConfigThis tells Next.js to process these packages through its build pipeline, converting the ES modules into a format that webpack can understand.
A few other things to check:
Make sure you're on a recent version of Next.js - The
transpilePackagesoption was added in Next.js 13.1. If you're on an older version, you might need to upgrade or use the oldernext-transpile-modulespackage.Verify your installation - Sometimes clearing your
node_modulesand reinstalling can help:rm -rf node_modules package-lock.json npm installCheck for conflicting versions - The
@sanity/orderable-document-listplugin has peer dependencies on@sanity/ui. Make sure your versions are compatible by checking the plugin's npm page.
After making these changes, restart your development server completely. The error should be resolved and you'll be able to use the orderable-document-list plugin to add drag-and-drop ordering to your documents!
Show original thread15 replies
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.