Sanity v2: Module parse error with sanity-plugin-icon-picker 2.1.0

5 replies
Last updated: Jun 2, 2023
Hi team, I am using sanity v2. I installed sanity-plugin-icon-picker 2.1.0. Then I got this wierd error. Hope to find help here. Thanks!
Error in ./node_modules/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.esm.js

Module parse failed: Unexpected token (326:6)

You may need an appropriate loader to handle this file type.

|       style = {},

|       tagName = "div",

|       ...rest

|     } = this.props;

|     const {

@ ./node_modules/sanity-plugin-icon-picker/dist/components/SearchResults.js 20:56-95

@ ./node_modules/sanity-plugin-icon-picker/dist/index.js

@ ./node_modules/sanity-plugin-icon-picker/dist/schemaType.js

@ ./node_modules/sanity-plugin-icon-picker/dist/schemaType.js (all:part:@sanity/base/schema-type)

@ ./schemas/schema.js (part:@sanity/base/schema)

@ ./node_modules/@sanity/vision/lib/SanityVision.js

@ ./node_modules/@sanity/vision/lib/VisionTool.js

@ ./node_modules/@sanity/vision/lib/VisionTool.js (all:part:@sanity/base/tool)

@ ./node_modules/@sanity/default-layout/lib/util/getRegisteredTools.js

@ ./node_modules/@sanity/default-layout/lib/router.js

@ ./node_modules/@sanity/default-layout/lib/Root.js (part:@sanity/base/root)

@ ./node_modules/@sanity/base/lib/components/SanityRoot.js (part:@sanity/base/sanity-root)

@ ./node_modules/@sanity/server/lib/browser/entry-dev.js

@ multi ./node_modules/@sanity/server/lib/browser/entry-dev.js
AI Update

This is a transpilation issue where react-virtualized-auto-sizer (a dependency of sanity-plugin-icon-picker) uses modern JavaScript syntax like spread operators (...rest) that Sanity Studio v2's webpack isn't configured to handle from node_modules by default.

The core problem: Sanity Studio v2 reached end-of-life on December 7, 2023 and no longer receives updates or support. The Parts System and webpack-based build tooling used in v2 don't automatically transpile modern JavaScript syntax from dependencies in node_modules, which is why you're seeing this error with newer plugin versions.

Your best paths forward:

1. Migrate to Sanity Studio v3 or v4 (Strongly Recommended)

This is the officially supported solution. Studio v3+ uses Vite instead of webpack and handles modern ESM packages without these transpilation issues. The migration process is documented and most projects can migrate in a few hours. This will also future-proof your project against similar dependency issues as the JavaScript ecosystem continues evolving.

2. Try a different or older version of the plugin

If you can't migrate immediately:

  • Try downgrading to an earlier version of sanity-plugin-icon-picker (before 2.1.0) that might use older dependencies without spread syntax issues
  • Look for an alternative icon picker plugin that's explicitly compatible with Studio v2
  • Consider building a simpler custom icon picker using v2-compatible dependencies

3. Custom webpack configuration

Studio v2 did support webpack customization through the Parts System. You can add a webpack config by creating a file and referencing it in your sanity.json:

{
  "parts": [
    {
      "implements": "part:@sanity/base/webpack-config",
      "path": "./webpack.config.js"
    }
  ]
}

Then create webpack.config.js in your studio root to configure babel-loader to transpile this specific dependency:

module.exports = {
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        include: /node_modules\/react-virtualized-auto-sizer/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react']
          }
        }
      }
    ]
  }
}

You may need to install babel dependencies: npm install --save-dev babel-loader @babel/core @babel/preset-env @babel/preset-react

However, since v2 is unsupported, you're likely to encounter more of these compatibility issues as third-party packages and their dependencies continue using modern JavaScript features. Migration to v3/v4 will save you significant troubleshooting time in the long run.

Show original thread
5 replies
Hi
user D
. Unfortunately, this will happen as more packages update to ES6 syntax (in the error above, it’s the
…rest
line) without polyfills for ancient bundlers like Webpack 3 (which is what v2 of the Studio uses). In this case, the
icon-picker
plugin depends on
^1.0.5
of
react-virtualized-auto-sizer
, meaning that it will update the dependency for anything up to but excluding
v2.0.0
. It looks like this PR made what ended up being breaking changes to the v2 version of the
icon-picker
plugin. Given the plugin’s package.json refers to
v1.0.5
of the dependency, I would try pinning to that by adding this to your Studio’s
package.json
file and running `npm i`:

"overrides": {
  "sanity-plugin-icon-picker": {
    "react-virtualized-auto-sizer": "1.0.5"
  }
}
If you’re using yarn, you can change
overrides
to
resolutions
and install accordingly.
If you can upgrade your Studio to v3, you won’t run into this problem anymore.
Thanks
user A
for a detailed feedback.
We are maintaining a legacy codebase 🙂We might be pushing for v3 sometime to take advantage of the new features.
🙂
Salamat!
I used the 2.0.0 versions instead and it solves the issue. 🙂

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?