nitrojs / nitrojs/nitro

Vitest working with Nitro v2, but not with Nitro v3.0.1-alpha.0

Open
#3,659 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement tanstack v3
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment

npx --yes envinfo --system --binaries

  System:
    OS: Linux 6.17 Arch Linux
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.10.0
    npm: 11.6.2
    pnpm: 10.18.3
Reproduction

https://github.com/theoludwig/vite-nitro-issues

Unfortunately this is not a "as minimal as possible reproduction", but I thought it was still worth to open the issue as an early tester of Nitro v3 alpha version, and that it was working with v2. The provided reproduction is a TanStack Start application following their documentation about Nitro usage: https://tanstack.com/start/latest/docs/framework/react/guide/hosting#using-nitro-v2

I haven't had time to investigate the issue further yet.

Describe the bug

node --run test which is using vitest run doesn't work with Nitro v3, but works with Nitro v2.

I did 2 commits in the reproduction example:

  • chore: nitro v2 which use @tanstack/nitro-v2-vite-plugin and has a green CI, no problems.
  • chore: nitro v3, with as you can see in the commit, the only change, is that it's using "nitro": "3.0.1-alpha.0", and the CI doesn't work (same behavior as locally), and fails with vitest run.
Additional context

No response

Logs
info Using tsconfig paths for react-docgen

⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot read properties of undefined (reading 'onMessage')
    at Object.on (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/nitro@3.0.1-alpha.0_vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6_/node_modules/nitro/dist/_chunks/plugin.mjs:348:13)
    at Object.setInvokeHandler (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vite/dist/node/chunks/dep-B0GuR2De.js:28475:16)
    at new DevEnvironment (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vite/dist/node/chunks/dep-B0GuR2De.js:35006:12)
    at new FetchableDevEnvironment (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/nitro@3.0.1-alpha.0_vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6_/node_modules/nitro/dist/_chunks/plugin.mjs:318:5)
    at createFetchableDevEnvironment (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/nitro@3.0.1-alpha.0_vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6_/node_modules/nitro/dist/_chunks/plugin.mjs:313:10)
    at Object.createEnvironment (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/nitro@3.0.1-alpha.0_vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6_/node_modules/nitro/dist/_chunks/plugin.mjs:525:50)
    at _createServer (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/vite@7.1.10_@types+node@24.7.2_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vite/dist/node/chunks/dep-B0GuR2De.js:27964:132)
    at async createViteServer (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/vitest@3.2.4_@types+node@24.7.2_@vitest+browser@3.2.4_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:6911:17)
    at async createVitest (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/vitest@3.2.4_@types+node@24.7.2_@vitest+browser@3.2.4_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:10202:17)
    at async prepareVitest (file:///home/runner/work/vite-nitro-issues/vite-nitro-issues/node_modules/.pnpm/vitest@3.2.4_@types+node@24.7.2_@vitest+browser@3.2.4_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:10541:14)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked vite-nitro-issues reproduction and compare the Nitro v2 and Nitro v3 commits. Run node --run test or vitest run, then inspect the Nitro plugin.mjs stack-trace path around the onMessage failure and Vite's setInvokeHandler. Done means the reproduction runs successfully with Nitro v3 without the startup error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript, vite
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.