Deployment issues when using Sanity Studio

I have a Next.JS (v14.2.4) project that uses Sanity CMS (v3).
Sanity is being deployed under /studio/* routes.

Builidng the project locally or building it inside Docker container works perfectly fine.
Building it on Netlify fails due to module imports fails.
Depending on the Sanity version I either get:

10:23:49 PM:   ▲ Next.js 14.2.4
10:23:49 PM:    Creating an optimized production build ...
10:24:25 PM: Failed to compile.
10:24:25 PM: 
10:24:25 PM: ./node_modules/sanity/lib/index.js
10:24:25 PM: Module not found: Package path ./theme is not exported from package /opt/build/repo/node_modules/sanity/node_modules/@sanity/ui (see exports field in /opt/build/repo/node_modules/sanity/node_modules/@sanity/ui/package.json)
10:24:25 PM: https://nextjs.org/docs/messages/module-not-found
10:24:25 PM: Import trace for requested module:
10:24:25 PM: ./node_modules/sanity-plugin-utils/lib/index.cjs
10:24:25 PM: ./node_modules/sanity-plugin-utils/lib/index.cjs.js
10:24:25 PM: ./node_modules/@sanity/orderable-document-list/lib/index.esm.js
10:24:25 PM: ./sanity.config.ts
10:24:25 PM: ./node_modules/sanity/lib/_chunks-es/generate-help-url.esm.mjs
10:24:25 PM: Attempted import error: 'TooltipDelayGroupProvider' is not exported from '@sanity/ui' (imported as 'TooltipDelayGroupProvider$1').
10:24:25 PM: Import trace for requested module:
10:24:25 PM: ./node_modules/sanity/lib/_chunks-es/generate-help-url.esm.mjs
10:24:25 PM: ./node_modules/sanity/lib/structure.mjs
10:24:25 PM: ./sanity.config.ts
10:24:25 PM: ./node_modules/sanity/lib/index.mjs
10:24:25 PM: Module not found: Package path ./theme is not exported from package /opt/build/repo/node_modules/sanity/node_modules/@sanity/ui (see exports field in /opt/build/repo/node_modules/sanity/node_modules/@sanity/ui/package.json)
10:24:25 PM: https://nextjs.org/docs/messages/module-not-found
10:24:25 PM: Import trace for requested module:
10:24:25 PM: ./sanity.config.ts
10:24:25 PM: > Build failed because of webpack errors
10:24:25 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)

or

10:00:10 PM:   ▲ Next.js 14.2.4
10:00:10 PM:    Creating an optimized production build ...
10:00:49 PM: Failed to compile.
10:00:49 PM: 
10:00:49 PM: ./node_modules/@sanity/vision/node_modules/@sanity/ui/dist/theme.mjs
10:00:49 PM: Attempted import error: 'color' is not exported from '@sanity/color' (imported as 'color').
10:00:49 PM: Import trace for requested module:
10:00:49 PM: ./node_modules/@sanity/vision/node_modules/@sanity/ui/dist/theme.mjs
10:00:49 PM: ./node_modules/@sanity/vision/node_modules/@sanity/ui/dist/index.mjs
10:00:49 PM: ./node_modules/@sanity/vision/lib/_chunks-es/SanityVision.mjs
10:00:49 PM: ./node_modules/@sanity/vision/lib/_chunks-es/index.mjs
10:00:49 PM: ./node_modules/@sanity/vision/lib/index.mjs
10:00:49 PM: ./sanity.config.ts
10:00:49 PM: ./node_modules/sanity/node_modules/@sanity/ui/dist/theme.mjs
10:00:49 PM: Attempted import error: 'color' is not exported from '@sanity/color' (imported as 'color').
10:00:49 PM: Import trace for requested module:
10:00:49 PM: ./node_modules/sanity/node_modules/@sanity/ui/dist/theme.mjs
10:00:49 PM: ./node_modules/sanity/lib/index.mjs
10:00:49 PM: ./sanity.config.ts
10:00:49 PM: > Build failed because of webpack errors
10:00:49 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
10:00:49 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is there anything I could do to fix this?

Do you have a reproduction to share so we can test?

I’m getting a similar issue but with styled-components: Attempted import error: 'styled' is not exported from 'styled-components' (imported as 'styled').

Sanity mentioned updating to styled-components v6 but I cannot since there are migration issues.

I guess why is this happening only netlify, and not local, or competitors.

A post above yours is asking for reproduction steps. Without that, there’s not much we can test.