deno
598f39d4 - fix(cli): clearer error when importing .node addon via ESM (#34361)

Commit
176 days ago
fix(cli): clearer error when importing .node addon via ESM (#34361) Importing a native `.node` addon through an ESM `import` statement previously surfaced as `SyntaxError: Unexpected character '\xff'` because the binary file was handed to V8 as JavaScript. Native addons in Node.js can only be loaded through `require()`, so detect the `.node` extension at the start of `load_inner` and return a `TypeError` that points users at `createRequire()` from `node:module`. The legitimate CJS paths (`import "npm:some-pkg"` where the package internally `require`s a `.node` file, and explicit `createRequire()` + `require("./addon.node")` in user code) are unaffected. Fixes #17246
Author
Parents
Loading