Issues with `@sanity/ui` in v3 plugin resolved by switching from Yarn to NPM

20 replies
Last updated: Feb 5, 2023
I upgraded to the latest version of
@sanity/ui
in my v3 plugin and now the builds fail complaining about missing props to every single sanity UI component. It’s fixed by adding these two props to all of them
_onResize_={undefined} _onResizeCapture_={undefined}
😅
AI Update

This is a known TypeScript issue that happens when there's a version mismatch between @types/react and @sanity/ui. The onResize and onResizeCapture props were added to React's type definitions in @types/react version 18.3.0+, and when styled-components-based libraries like Sanity UI don't explicitly include these props in their component types, TypeScript throws errors.

Here are a few solutions, from quickest to most thorough:

Option 1: Downgrade @types/react (quickest fix)

The easiest solution is to pin @types/react to version 18.2.x:

npm install --save-dev @types/react@18.2.79 @types/react-dom@18.2.25

This avoids the new resize props that are causing the issue.

Option 2: Upgrade @sanity/ui

Make sure you're on the latest version of @sanity/ui, as newer versions may have better compatibility:

npm install @sanity/ui@latest

Option 3: Create a type augmentation file

If you need to keep your current versions, instead of adding those props to every component manually, create a sanity-ui.d.ts file in your project root:

import 'react'

declare module 'react' {
  interface DOMAttributes<T> {
    onResize?: ReactEventHandler<T> | undefined
    onResizeCapture?: ReactEventHandler<T> | undefined
  }
}

export {}

This tells TypeScript that these props are optional across all React components, which is effectively what they should be.

Option 4: Check your dependency versions

For Sanity Studio v3 plugins, ensure your peer dependencies are aligned. Your package.json should have compatible versions of:

  • react and react-dom (typically ^18)
  • styled-components (^6.1 for Studio v3)
  • Their corresponding @types/* packages

This is fundamentally a TypeScript ecosystem compatibility issue between React types and styled-components, not a bug in Sanity UI itself. The downgrade to @types/react@18.2.x is usually the fastest path forward while the ecosystem catches up.

I know you want V3 feedback on Github. But not sure if this is V3 or Sanity UI related
It happens in the plugin package itself, not the V3 studio
Then running it in the V3 studio after linking up I get the following errors:

Could not resolve "@reach/auto-id"

Could not resolve "react-popper"

Could not resolve "popper-max-size-modifier"

All imported by Sanity UI lib.

All have the following info after:


You can mark the path "<insert-lib-from-above-list>" as external to exclude it from the bundle,  which will remove this error.
Hello! Can you try updating
@types/react
in your plugin?
Thanks, tried it but it didn’t work 😕
Hello
user S
I just stumbled over this message here, are you still experiencing this issue?
Hey
user J
thanks for checking. I managed to get this working again
What did you do (so when people have the same issue, they can find an answer here 🙂 )
Oh, haha, honestly I don't know. I left it for a few weeks, then tried again. Got different errors and resolved those instead 😅
#caption "programming" spongebob rainbow
hey
user J
this actually wasn’t fixed. The builds stopped failing, but vscode keeps complaining with red squiggly lines on Flex and Box from Sanity UI.
Hadn’t opened the custom input component I built in a while so I didn’t notice until today when I had to dig in there again for a different issue (I’m using the same custom input component on 2 different fields in the same doc but only one gets updated, even when I click the other one)
It might just be a TS issue with sanity/ui, could you try to update the package?
I upgraded sanity/ui but the issue is still there
adding the props removes the warning
latest version of TS (4.9.4)
Just bumping this thread to say I’m also getting this issue in a Sanity project I’m working on.
I still haven’t solved it either
Actually - I think I may have a fix.
user S
Just on a whim, I switched my package management on the project I’m in from Yarn 1.22 to NPM 8.19.3. Knocked out my node_modules and did a full reinstall. Seemingly solved at the moment.
right, so it’s a yarn issue. I’m working on a local plugin that’s currently linked with yalc/yarn link. Would need to update that first to test this out. We’re also using yarn for everything else. So would definitely prefer that it works for both yarn and npm.
user J
it looks like Andy found the cause

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?