Module not found error after Sanity upgrade: Can't resolve '../../utils/patches

15 replies
Last updated: Mar 5, 2021
Just did an sanity upgrade and getting these errors ... anyone seen this or have any ideas? I've done several upgrades before no problem. I am using OOTB studio.
✔ Checking project info
✔ Clearing output folder (7ms)
✖ Building Sanity

Error: Errors while building:
./node_modules/@sanity/form-builder/lib/sanity/uploads/uploaders.js
Module not found: Error: Can't resolve '../../utils/patches' in '/home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/lib/sanity/uploads'
resolve '../../utils/patches' in '/home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/lib/sanity/uploads'
  using description file: /home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/package.json (relative path: ./lib/sanity/uploads)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/package.json (relative path: ./lib/sanity/uploads)
    using description file: /home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/package.json (relative path: ./lib/utils/patches)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/lib/utils/patches doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /home/x/dev/projects/c4c/climbing4change-cms/node_modules/@sanity/form-builder/lib/utils/patches.js doesn't exist
      .jsx
...
AI Update

This looks like a classic case of mixed or corrupted dependencies after an upgrade. The @sanity/form-builder package was a standalone package in Sanity Studio v2, but it's been fully integrated into the core sanity package since Studio v3. This error usually means you have remnants of old packages in your node_modules.

Here's how to fix it:

1. Clean install (most likely solution):

rm -rf node_modules
rm package-lock.json  # or yarn.lock / pnpm-lock.yaml
npm install

2. Check your package.json:

Make sure you don't have @sanity/form-builder explicitly listed as a dependency. In Studio v3+, you should only have:

{
  "dependencies": {
    "sanity": "^3.x.x"  // or whatever your version is
  }
}

If @sanity/form-builder is there, remove it and reinstall.

3. Check for outdated plugins:

Sometimes custom plugins or older third-party packages still depend on @sanity/form-builder. Run:

npm ls @sanity/form-builder

If anything shows up, those packages need updating to be compatible with Studio v3+.

4. Verify your Studio version:

  • If you have a sanity.json file in your project root, you're still on Studio v2 and need to migrate to v3
  • Make sure you're on Node.js 18+ (Node.js 20+ is required for Studio v4)

Why this happens:

The @sanity/form-builder package hasn't been maintained since Studio v3 was released. When upgrading, if the old package isn't fully removed, webpack/bundler tries to resolve the old internal file structure (like ../../utils/patches) which no longer exists. A clean install usually clears this up completely.

If you're still stuck after trying these steps, check if any custom input components in your schema are importing directly from @sanity/form-builder - those would need to be updated to import from sanity instead.

Show original thread
15 replies
Same on an old studio I was trying to revisit earlier, actually!
Wasn’t urgent so I’ve left it for now but would love to know if there is a solution for this. I was deleting node_modules etc. but haven’t made the situation better…
My last upgrade was only 2 days ago, unfortunately.
user K
user P
If you wouldn’t mind trying something, could you copy 
node_modules/@sanity/form-builder/lib/patch/patches.js
 into 
node_modules/@sanity/form-builder/lib/utils
? The file should exist in both places (just until this is resolved in a future release). It looks like for some reason, there’s a problem resolving the import.
hmmm - i got through compilation successfully by copying the file as you recommended, but for some reason I can't get to the site when doing sanity start (connection refused at localhost:3333). But perhaps that's something else going on.
What’s even weirder is that I just tried running a project that I bootstrapped yesterday—same versions of everything—and it started up without issue.
I’m only having trouble on old versions that I upgraded to 2.6.0.
looking at my git history, I went from 2.5.0 to 2.6.0 and encountered the issue.
Wow, this bug is weird. It looks like yarn has upgraded the form-builder package, but somehow doesn't have the right contents. The tarball on npm has the right version, but it seems after upgrade not to have overwritten the actual content in node_modules..
I'll see if I can publish a version that aliases to the right place, for now
Published v2.6.1 - should hopefully be fixed if you upgrade now!
awesome thanks Espen -- I'll try it out!
This worked for me. Appreciate the quick help
user Z
and
user A
! 👏
Glad to hear it, Malcolm!

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?