v3 migration error: sanity-plugin-media using incompatible "part:" imports
I followed the
migration guide but I have run into an error that I am blocked on. (I have deleted and re-installed node_modules and package-lock.json and run installs of plugins to get latest versions).
The error looks like this:
✔ Checking configuration files...
Sanity Studio using vite@4.0.4 ready in 3258ms and running at <http://localhost:3333/>
✘ [ERROR] Could not resolve "part:@sanity/base/image-icon"
node_modules/sanity-plugin-media/dist/index.js:6:43:
6 │ ...image_icon_1 = __importDefault(require("part:@sanity/base/image-icon"));
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "part:@sanity/base/image-icon" as external to exclude it from
the bundle, which will remove this error. You can also surround this "require" call
with a try/catch block to handle this failure at run-time instead of bundle-time.
✘ [ERROR] Could not resolve "part:@sanity/base/client"
node_modules/sanity-plugin-media/dist/client.js:7:39:
7 │ var client_1 = __importDefault(require("part:@sanity/base/client"));
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "part:@sanity/base/client" as external to exclude it from the
bundle, which will remove this error. You can also surround this "require" call
with a try/catch block to handle this failure at run-time instead of bundle-time.
✘ [ERROR] Could not resolve "part:@sanity/base/router"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:11:23:
11 │ var router_1 = require("part:@sanity/base/router");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "part:@sanity/base/router" as external to exclude it from the
bundle, which will remove this error. You can also surround this "require" call
with a try/catch block to handle this failure at run-time instead of bundle-time.
✘ [ERROR] Could not resolve "part:@sanity/base/preview"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:12:40:
12 │ var preview_1 = __importDefault(require("part:@sanity/base/preview"));
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "part:@sanity/base/preview" as external to exclude it from
the bundle, which will remove this error. You can also surround this "require" call
with a try/catch block to handle this failure at run-time instead of bundle-time.
✘ [ERROR] Could not resolve "part:@sanity/base/schema"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:13:39:
13 │ var schema_1 = __importDefault(require("part:@sanity/base/schema"));
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "part:@sanity/base/schema" as external to exclude it from the
bundle, which will remove this error. You can also surround this "require" call
with a try/catch block to handle this failure at run-time instead of bundle-time.
✘ [ERROR] Could not resolve "part:@sanity/base/with-referring-documents"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:14:41:
14 │ ...ng_documents_1 = require("part:@sanity/base/with-referring-documents");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "part:@sanity/base/with-referring-documents" as external to
exclude it from the bundle, which will remove this error. You can also surround
this "require" call with a try/catch block to handle this failure at run-time
instead of bundle-time.
5:58:30 PM [vite] error while updating dependencies:
Error: Build failed with 6 errors:
node_modules/sanity-plugin-media/dist/client.js:7:39: ERROR: Could not resolve "part:@sanity/base/client"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:11:23: ERROR: Could not resolve "part:@sanity/base/router"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:12:40: ERROR: Could not resolve "part:@sanity/base/preview"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:13:39: ERROR: Could not resolve "part:@sanity/base/schema"
node_modules/sanity-plugin-media/dist/components/DocumentList/index.js:14:41: ERROR: Could not resolve "part:@sanity/base/with-referring-documents"
...
at failureErrorWithLog (/Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:1604:15)
at /Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:1056:28
at runOnEndCallbacks (/Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:1476:61)
at buildResponseToResult (/Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:1054:7)
at /Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:1166:14
at responseCallbacks.<computed> (/Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:701:9)
at handleIncomingPacket (/Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:756:9)
at Socket.readFromStdout (/Users/henrybabbage/Repos/bortolozzi/studio/node_modules/esbuild/lib/main.js:677:7)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
^CMany thanks in advance.
The error you're encountering is because you have the Studio v2 version of sanity-plugin-media installed, which uses the deprecated Parts System (part:@sanity/base/* imports). These parts were completely removed in Studio v3.
The good news is that sanity-plugin-media does have a v3-compatible version—it's the same package name, but you need to ensure you're installing the correct version. Here's how to fix it:
Uninstall the old version:
npm uninstall sanity-plugin-mediaInstall the Studio v3 compatible version:
npm install sanity-plugin-media@studio-v3Alternatively, if the latest version is v3-compatible (which it should be now), you can use:
npm install sanity-plugin-media@latestUpdate your
sanity.config.ts(or.js) file:The plugin configuration syntax has changed for v3. Make sure you're importing and using it correctly:
import { defineConfig } from 'sanity' import { media } from 'sanity-plugin-media' export default defineConfig({ // ... other config plugins: [ media() // ... other plugins ] })Clean install: After updating, delete
node_modulesandpackage-lock.json, then runnpm installfresh.
The key issue is that during migration, npm may have kept the v2 version of the plugin in your dependencies. By explicitly installing the @studio-v3 tag or @latest, you ensure you get the v3-compatible version that doesn't use the old parts system.
Additional note: If you're on an Enterprise plan, you might also want to explore Sanity's built-in Media Library feature, which is an organization-scoped DAM addon with enhanced capabilities like metadata management, versioning, and GROQ queries. But sanity-plugin-media works great for most use cases and is available on all plans.
Show original thread3 replies
Was this answer helpful?
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.