alex
alex3mo ago

deno_node

I imported deno_node as extension to support node API for my runtime using deno_core but I'm still getting this error: .cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.307.0/runtime/jsruntime.rs:724:9: Failed to initialize a JsRuntime: Uncaught SyntaxError: Unexpected token '{' at ext:deno_node/_http_outgoing.ts:12:13 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
6 Replies
bartlomieju
bartlomieju3mo ago
You will need to import a lot more ext/ crate from Deno to make deno_node work And the error you are getting is because you didn't provide a transpiler option when configuring your JsRuntime
bartlomieju
bartlomieju3mo ago
GitHub
deno/runtime/shared.rs at 3138478f66823348eb745c7f0c2d34eed378a3f0 ...
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.
alex
alexOP3mo ago
@bartlomieju in meantime I figured out myself, my other question is that, how is that deno says it supports Node but it breaks when I execute a script which uses Buffer.from?
bartlomieju
bartlomieju3mo ago
You need to import it: import { Buffer } from "node:buffer"; Deno doesn't expose all Node globals to user code on purpose
alex
alexOP3mo ago
@bartlomieju what is the reason for?
bartlomieju
bartlomieju3mo ago
Node globals are all available in the npm packages, but limited to process in user code. It's mostly because Deno prefers Web APIs and some Deno globals conflict with Web APIs (eg. setTimeout has different return type in Node than in the browser). And Buffer is one of the globals that we don't expose