ginpacc
ginpacc3mo ago

node:worker_threads "Module not found"

After compiling the exe with deno compile, executing the exe reports an error "Module not found", but the path is a real script System: windows11 Deno 1.45.5
No description
3 Replies
Deno AI Helper
Deno AI Helper3mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the message you've provided, it seems like you might be referencing Node.js-specific functionality (node:worker_threads) which is not available in Deno. Deno has its own way of handling worker threads using the Worker API. If you're trying to use Node.js-style worker threads in Deno, that would not work because Deno does not support Node.js modules out of the box. Instead, you should use Deno's built-in Worker API. Here's a basic example of how to use workers in Deno:
// main.ts
const worker = new Worker(new URL("worker.ts", import.meta.url).href, { type: "module" });
worker.postMessage("Hello, worker!");

// worker.ts
self.onmessage = (e) => {
console.log("Received from main script:", e.data);
self.close();
};
// main.ts
const worker = new Worker(new URL("worker.ts", import.meta.url).href, { type: "module" });
worker.postMessage("Hello, worker!");

// worker.ts
self.onmessage = (e) => {
console.log("Received from main script:", e.data);
self.close();
};
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice and consult the Deno documentation or community for further assistance.
Thomas
Thomas3mo ago
Hi, demo compile cannot know what kind of worker file is loaded. You can use --include to specify which file should be included.
ginpacc
ginpacc3mo ago
Yes, I have used --include, and it has already failed when loading into Worker