Skip to content

refactor: replace vite-node with Vite's native RunnableDevEnvironment#1716

Closed
lisa-assistant wants to merge 6 commits intocedarjs:mainfrom
lisa-assistant:lisa/replace-vite-node-with-vite-runner
Closed

refactor: replace vite-node with Vite's native RunnableDevEnvironment#1716
lisa-assistant wants to merge 6 commits intocedarjs:mainfrom
lisa-assistant:lisa/replace-vite-node-with-vite-runner

Conversation

@lisa-assistant
Copy link
Copy Markdown
Contributor

Summary

vite-node is a separate package that replicates functionality now built directly into Vite via the Environment API (introduced in Vite 6, and we're on Vite 7).

This replaces ViteNodeServer + ViteNodeRunner + installSourcemapsSupport with Vite's native RunnableDevEnvironment:

Before:

const node = new ViteNodeServer(server, { ... })
installSourcemapsSupport({ getSourceMap: (source) => node.getSourceMap(source) })
const runner = new ViteNodeRunner({ root, base, fetchModule, resolveId })
const result = await runner.executeFile(filePath)

After:

// In server config:
environments: { nodeRunnerEnv: {} }

// Then:
const env = server.environments.nodeRunnerEnv
if (!isRunnableDevEnvironment(env)) throw new Error(...)
const result = await env.runner.import(filePath)

Files changed

  • packages/cli/src/lib/exec.js — used by yarn cedar exec (script runner)
  • packages/prerender/src/graphql/node-runner.ts — used by prerender's GraphQL node runner
  • Both package.json files — vite-node dependency removed

Inspired by

remix-run/react-router#14862

🤖 Generated with Claude Code

@netlify
Copy link
Copy Markdown

netlify Bot commented May 4, 2026

👷 Deploy request for cedarjs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ab1fb61

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR removes the vite-node package from both packages/cli and packages/prerender, replacing ViteNodeServer + ViteNodeRunner with Vite's native RunnableDevEnvironment API introduced in Vite 6. The docs in docs/implementation-docs/2026-03-26-cedarjs-project-overview.md remain factually correct — they reference Vite 7 and do not mention vite-node.

  • node-runner.ts's init() does not close this.viteServer before throwing when the isRunnableDevEnvironment guard fails, leaking the server. exec.js handles the identical guard correctly with await server.close() — the same fix is needed in NodeRunner.init().

Confidence Score: 4/5

Safe to merge after fixing the Vite server resource leak in NodeRunner.init().

The migration is clean and consistent across both packages. One gap stands out: when NodeRunner.init() determines the environment is not runnable, it throws without closing the already-created Vite server, leaving file watchers open. The parallel code path in exec.js closes the server before throwing, so the fix is straightforward.

packages/prerender/src/graphql/node-runner.ts — the init() guard path needs server cleanup before throwing.

Important Files Changed

Filename Overview
packages/cli/src/lib/exec.js Replaces vite-node with RunnableDevEnvironment; guard failure path correctly closes the server before throwing; hmr/watch disabled for one-shot use.
packages/prerender/src/graphql/node-runner.ts Replaces vite-node with RunnableDevEnvironment; init() leaks the Vite server when the isRunnableDevEnvironment guard fires, unlike the parallel fix in exec.js.
packages/cli/package.json Removes vite-node dependency.
packages/prerender/package.json Removes vite-node dependency.

Reviews (2): Last reviewed commit: "refactor: address review feedback + expl..." | Re-trigger Greptile

Comment thread packages/prerender/src/graphql/node-runner.ts Outdated
Comment thread packages/cli/src/lib/exec.js
Comment on lines +66 to +69
const env = this.viteServer.environments.nodeRunnerEnv
if (!env || !isRunnableDevEnvironment(env)) {
throw new Error('Vite environment is not runnable.')
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 If isRunnableDevEnvironment returns false, this.viteServer has already been created and assigned but is never closed before the error is thrown. This leaves file watchers and potentially a listening port open. exec.js handles the identical guard correctly with await server.close() before throwing — the same pattern should be applied here.

Suggested change
const env = this.viteServer.environments.nodeRunnerEnv
if (!env || !isRunnableDevEnvironment(env)) {
throw new Error('Vite environment is not runnable.')
}
const env = this.viteServer.environments.nodeRunnerEnv
if (!env || !isRunnableDevEnvironment(env)) {
await this.viteServer.close()
throw new Error('Vite environment is not runnable.')
}

@lisa-assistant lisa-assistant deleted the lisa/replace-vite-node-with-vite-runner branch May 5, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant