fix: workspace-relative openInEditor paths resolve against cwd and double the package prefix in monorepos
đ The bug
In a pnpm monorepo, Component Inspector â Open in Editor fails with a doubled package path:
File not found: <repo>/apps/web/apps/web/app/features/.../SomeComponent.vue
Expected file:
<repo>/apps/web/app/features/.../SomeComponent.vue
(Same pattern for any package under apps/<name>/, e.g. previously apps/app â apps/app/apps/app/....)
Why
openInEditor resolves non-absolute paths with process.cwd() (the Nuxt package root, e.g. apps/web):
if (input.startsWith("./") || !ABSOLUTE_PATH_RE.test(input))
input = resolve(process.cwd(), input)
The inspector often sends a workspace-relative path like:
apps/web/app/features/.../SomeComponent.vue
So:
cwd (= âĻ/apps/web) + apps/web/app/... â âĻ/apps/web/apps/web/app/...
existsSync then fails and returns before openInEditorHooks run, so hooks cannot fix the path.
Nuxt already exposes nuxt.options.workspaceDir for monorepos, but it is not used here.
đ ī¸ To reproduce
pnpm monorepo with Nuxt at apps/web â pnpm --filter
đ Expected behavior
Resolve relative open-in-editor paths against nuxt.options.workspaceDir (and/or try cwd â rootDir â workspaceDir and pick the first path that exists), then open the file.
Ideally openInEditorHooks should also run (or path normalization should happen) before the hard existsSync failure, so consumers can fix monorepo paths.
âšī¸ Additional context
Detailed reproduction
- pnpm workspace with Nuxt app at
apps/web(not repo root). - Run
pnpm --filter <app> devsoprocess.cwd()isapps/web. - Enable Component Inspector, click a component, Open in Editor.
- Observe
File not found: âĻ/apps/web/apps/web/app/....
Minimal layout:
repo/
pnpm-workspace.yaml # packages: ['apps/*']
apps/
web/ # Nuxt app (cwd when running nuxt dev)
app/
components/
Foo.vue
Environment
- Nuxt:
4.5.x @nuxt/devtools:3.4.x(via Nuxt)- Package manager: pnpm workspace
- OS: Windows 10/11
Workaround
Local Nuxt module wrapping the DevTools RPC openInEditor to rewrite the path (try cwd / rootDir / workspaceDir + undouble apps/<pkg>/apps/<pkg>/âĻ) before calling the original handler.
Also set:
// nuxt.config.ts
workspaceDir: fileURLToPath(new URL('../..', import.meta.url)), // monorepo root
Related
- Possibly related UX issues with inspector â editor: https://github.com/nuxt/devtools/issues/862
- Vite DevTools direction: resolve against
workspaceRootfor open-in-editor
Hitting this exact bug. Setup details:
OS: Windows 11 Nuxt: 4.5.2 @nuxt/devtools: 3.4.2 Vite: 8.3.1 Package manager: pnpm workspace monorepo Structure:
myrepo/ apps/my-app/ â nuxi dev runs here (rootDir) layers/order-core/ layers/shared-base/ layers/user-editor/ Layers consumed as pnpm workspace packages (@myrepo/order-core etc.) via extends, not relative paths.
Errors â layer component:
File not found: /myrepo/apps/my-app/layers/order-core/app/components/Widget.vue Should be: /myrepo/layers/order-core/app/components/Widget.vue
Errors â local app page:
File not found: /myrepo/apps/my-app/apps/my-app/app/pages/index.vue Should be: /myrepo/apps/my-app/app/pages/index.vue
Paths are workspace-root-relative but resolved against rootDir. Removing preserveSymlinks, explicitly setting workspaceDir, and Vite middleware on /__open-in-editor do not fix it â the RPC handler bypasses all of that. Been broken for a while now across multiple devtools versions. Please also consider whether #1098 will be backported to v3 or only land in v4.
Workaround found â no patch needed:
Root cause confirmed: openInEditor resolves relative paths using process.cwd() (line ~10500 in dist/chunks/module-main.mjs). When dev is run via pnpm --filter ./apps/my-app dev, pnpm changes into the app directory first, so process.cwd() = the app dir, not the workspace root â causing all paths to be resolved against the wrong base.
Fix: Run nuxi dev apps/my-app from the workspace root instead. Add to root package.json:
"dev:myapp": "nuxi dev apps/my-app" process.cwd() stays as the workspace root, relative paths resolve correctly, inspector works perfectly. Setting workspaceDir in nuxt.config.ts has no effect â only process.cwd() matters here.
This is still the case on @nuxt/[email protected], which Nuxt 4.6 installs. #1098 landed on main only.
With the Nuxt app in docs/ and the component at the workspace root, the inspector sends src/components/button/Button.demo.vue:27:2 and 3.4.4 logs File not found: <repo>/docs/src/components/button/Button.demo.vue. I'll open a PR against v3.