Skip to content

Nuxt: Breaking ESM Issue Prevents Using Nuxt 4 #3266

@rylanharper

Description

@rylanharper

Describe the bug

Hey Sanity team, I just want to bring attention to a breaking issue on the @nuxtjs/sanity module, which is preventing many devs from upgrading to Nuxt v4. This is detailed in this issue thread here.

The main gist of everything is that whenever the sub-dependencies of Visual Editing change, this causes ESM compatibility issues that require constant updates to optimizeDeps in Vite. These dependencies often aren’t valid ESM, and whether or not they break depends on how they’re hoisted by the package manager. You can see Daniel Roe's response to this here.

This has become a recurring cat-and-mouse problem where fixes are temporary until the Sanity dependency tree changes again. I'm really not sure of the solution and its at the point where this is likely affecting many Nuxt/Vue developers looking to upgrade to the latest version of Nuxt (a lot pf agencies that I have contracted for now use Nuxt + Sanity for their tech stack).

Oddly enough, the only fix I have found is separating out the app repo from the studio repo for Sanity to work properly with Nuxt 4, but after many hours of testing, I still cannot find why this actually works. I also understand this non-monorepo approach is not optimal for a lot of devs.

I mainly just wanted to bring this to the attention of the Sanity Visual Editing team. Perhaps there is a fix for this, or something can be added to the Nuxt module to make things smoother.

To Reproduce

I believe another dev has created a repo here, to test this issue.

Expected behavior

The @nuxtjs/sanity should work with the latest version of Nuxt 4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions