honojs / vite-plugins

Vite Plugins for Hono
https://hono.dev
134 stars 35 forks source link

Vite dev server crashes if error is introduced in the Hono Server. #132

Closed Blankeos closed 6 months ago

Blankeos commented 7 months ago

If you run vite dev then introduce a syntax error in index.ts and any of the files that are running the Hono server, the dev server crashes and fails to restart, and the process crashes.

Somewhat same motivations as in Rich's words from this issue: https://github.com/vitejs/vite/issues/12375

Ideally the process would stay alive, and gracefully recover once the error is fixed. Even better would be if the server survived, if only to report the error, though that's probably somewhat trickier.

Steps to reproduce:

  1. Clone and run this repo: https://github.com/Blankeos/spend-snap/tree/029cb1bbe64b17c05290b8399772ab60a94ec56b
  2. Introduce a syntax error anywhere in src/server/index.ts or _app.ts
  3. To run the server bun run dev:
    • Currently running it in node: vite
    • Can also run it in Bun bunx --bun vite
  4. Either way, try introducing an error AND both would still crash the dev server without restarts.

System

System Info
System:
    OS: macOS 14.4.1
  Binaries:
    Bun: 1.1.6

Error vite

View Error ``` 9:03:50 PM [vite] page reload src/server/_app.ts [vite] program reload /Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:1651 let error = new Error(text); ^ Error: Transform failed with 1 error: /Users/carlo/Desktop/Projects/spend-snap/src/server/_app.ts:13:35: ERROR: Expected ")" but found ";" at failureErrorWithLog (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:1651:15) at /Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:849:29 at responseCallbacks. (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:704:9) at handleIncomingPacket (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:764:9) at Socket.readFromStdout (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:680:7) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) at Socket.Readable.push (node:internal/streams/readable:390:5) at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) error: script "dev" exited with code 1 ```

Error bunx --bun vite

View Error ``` 9:16:57 PM [vite] page reload src/server/modules/collations/collations.controller.ts [vite] program reload 1646 | let { file, line, column } = e.location; 1647 | let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : ""; 1648 | return ` 1649 | ${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`; 1650 | }).join(""); 1651 | let error = new Error(text); ^ error: Transform failed with 1 error: /Users/carlo/Desktop/Projects/spend-snap/src/server/modules/collations/collations.controller.ts:4:30: ERROR: Expected ";" but found "(" errors: [ { "id": "", "location": { "column": 30, "file": "/Users/carlo/Desktop/Projects/spend-snap/src/server/modules/collations/collations.controller.ts", "length": 1, "line": 4, "lineText": "export const collationsControl().basePath(\"/collations\");", "namespace": "", "suggestion": ";" }, "notes": [], "pluginName": "", "text": "Expected \";\" but found \"(\"" } ] at failureErrorWithLog (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:1651:15) at /Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:849:29 at /Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:704:9 at handleIncomingPacket (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:764:9) at readFromStdout (/Users/carlo/Desktop/Projects/spend-snap/node_modules/vite/node_modules/esbuild/lib/main.js:680:7) at addChunk (node:stream:1953:43) at readableAddChunk (node:stream:1907:59) at node:stream:32:101 at node:stream:125:103 error: script "dev" exited with code 1 ```

The errors aren't really important. It's the fact that it closes when there's an error.

yusukebe commented 6 months ago

Hi @Blankeos

I've released @hono/vite-dev-server@0.12.1 to fix this issue. Could you try it?

Blankeos commented 6 months ago

@yusukebe Can confirm it works! Thanks so much!!

image