v3 migration error: sanity-plugin-media using incompatible "part:" imports

3 replies
Last updated: Jan 26, 2023
Hello, I have a #v3 migration question.
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)
^C
Familiar at all? Any suggestions?

Many thanks in advance.
AI Update

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:

  1. Uninstall the old version:

    npm uninstall sanity-plugin-media
  2. Install the Studio v3 compatible version:

    npm install sanity-plugin-media@studio-v3

    Alternatively, if the latest version is v3-compatible (which it should be now), you can use:

    npm install sanity-plugin-media@latest
  3. Update 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
      ]
    })
  4. Clean install: After updating, delete node_modules and package-lock.json, then run npm install fresh.

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 thread
3 replies
Hi Henry. It looks like v1.5.1 or earlier of the
media
plugin is getting installed. What does your package.json look like?
Hi Geoff, you were right. I just needed to uninstall the media plugin and that got the studio running, and then I reinstalled the media plugin with --force and I got the updated version and now everything is working fine. I should have been a bit more patient! Thank you!
Glad to hear you’re up and running! πŸ™Œ

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?