deno: [node-compat] Getting `BadResource: Bad resource ID` on accessing console or process.stdout
Hey folks, getting this error when trying to make vitepress work with Deno.
error: Uncaught (in promise) BadResource: Bad resource ID
at Object.isatty (ext:runtime/40_tty.js:19:7)
at Writable.get [as isTTY] (ext:deno_node/_process/streams.mjs:57:31)
at createLogger (file:///Users/divyansh/foo/node_modules/.deno/vitepress@1.0.0-beta.1/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:12736:63)
at file:///Users/divyansh/foo/node_modules/.deno/vitepress@1.0.0-beta.1/node_modules/vitepress/dist/node/cli.js:397:5
at Object.runMicrotasks (ext:core/01_core.js:836:30)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:51:14)
at runNextTicks (ext:deno_node/_next_tick.ts:69:5)
at eventLoopTick (ext:core/01_core.js:188:21)
Reproduction: https://github.com/brc-dd/vitepress-on-deno (run deno task dev)
Removing console logging things seems to prevent the issue. Not completely sure what the cause is.
Quick checking suggests that any console.log statements before the createServer call work fine, but after that invocation, they tend to fail. Likely is due to something that createServer is doing.
Version details:
deno 1.34.0 (release, aarch64-apple-darwin)
v8 11.5.150.1
typescript 5.0.4
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 31 (20 by maintainers)
Commits related to this issue
- fix(node): don't close stdio streams (#19256) Closes https://github.com/denoland/deno/issues/19255 --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com> — committed to denoland/deno by bartlomieju a year ago
- fix(node): don't close stdio streams (#19256) Closes https://github.com/denoland/deno/issues/19255 --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com> — committed to denoland/deno by bartlomieju a year ago
Thanks for the heads up @brc-dd. We are still trying to debug the problem with signals. Let’s keep this issue open.
🙏 thanks, I’d appreciate a separate issue. A reproduction would be enough for us to figure out the problem.
Thanks! The problem seems to be with the
oraspinner module.Here is a smaller reproduction:
No. Directly calling process.exit works, but it terminates the process before streams can finish (if the user has something in build hooks).
I think I just found a test case in Node that describes the behavior:
Does
vitepressexplicitly callprocess.exit()?EDIT: Actually it seems that raw mode should be reset even if existing cleanly without
process.exit()(test/pseudo-tty/test-set-raw-mode-reset.js)You should bump vitepress version. That
matchMediathing was fixed by checkingtypeof document !== 'undefined'instead of checkingwindowone.Yeah. I hadn’t checked by pressing enter though 😅
@brc-dd this fix will be available in Deno v1.34.2 to be released next week.
I’ve got a tentative fix ready that makes vitepress work.
Something is closing rid 1 (which is
stdout). I will dig deeper to find what causes that.