denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.98k stars 5.23k forks source link

deno compile: node addons gets error `missing symbol called` #24614

Open Mutefish0 opened 2 months ago

Mutefish0 commented 2 months ago

require('xxx.node') will get error missing symbol called after deno compile.

Version:

deno 1.45.1 (release, aarch64-apple-darwin)
v8 12.7.224.12
typescript 5.5.2

Reproduce

copy file audio.node: https://github.com/Mutefish0/deno-node-addons-issue/blob/master/audio.node

create main.ts

import Module from 'node:module'
import path from "node:path";

const standalone = Deno.args.includes("--standalone");

export function resolvePath(url: string, metaUrl: string) {
  let baseDir = "";
  if (standalone) {
    baseDir = path.dirname(Deno.execPath());
  } else {
    baseDir = path.dirname(metaUrl);
  }
  baseDir = baseDir.replace("file://", "");
  return path.resolve(baseDir, url);
}

const mod = new Module('')

const url = resolvePath("./audio.node", import.meta.url);

if (Deno.statSync(url).isFile) {
  const m = mod.require(url);
  console.log(m);
}

compile and run:

deno compile  --allow-ffi --allow-read   --output ./main  ./main.ts --standalone
./main

then the error occurs:

截屏2024-07-17 下午1 24 34

deno run:

deno run --allow-ffi --allow-read  ./main.ts

works fine:

截屏2024-07-17 下午1 30 00

reproduce repo: https://github.com/Mutefish0/deno-node-addons-issue

Mutefish0 commented 1 month ago

Reopen the issue since the PR(https://github.com/denoland/deno/pull/24642) was reverted. @devsnek Can this PR get relanded or is there any plan to address this issue?