Skip to content

useSanity import in server handlers sometimes breaks dev build #1077

Description

@rdunk

Overview

Using this module sometimes causes an error when running the dev server:

ERROR [worker reload] [worker init] ../.nuxt/dev/index.mjs failed

Related to nuxt/nuxt#29882, which I understand is likely an upstream/nitro issue. I wanted to open this here for visibility and see if anyone else could share insight in the context of this module. I'll continue to investigate to see if I can open an issue/PR in the nitropack repo.

The culprit seems to be when importing useSanity in a server handler. With this import removed, I find the consuming app runs consistently. Likewise I've found disabling visual editing (which therefore means addServerHandler is never called) resolves the issue.

It's a bit hard to pin down the exact reason. I suppose it's related to how Nitro is resolving virtual imports when using #imports, and results seem to vary depending on the location of those imports. For example running the playground app in this repo seems to work fine, but building the module locally and linking it using pnpm triggers the error (so long as these server handlers are called).

Version

module: 1.12.2
nuxt: 3.14.159

Reproduction

What is expected?

Importing useSanity via #imports in a server handler should work.

What is actually happening?

Importing useSanity via #imports in a server handler is sometimes causing nuxt dev to fail.

Steps to reproduce

Install the module and enable visual editing in a Nuxt app using Nitropack >2.10.0.

Additional information

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingupstream

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions