const Worker = require("worker_threads");const w = (new Worker(`const self = require("worker_threads");`, { eval: true }))();
const Worker = require("worker_threads");const w = (new Worker(`const self = require("worker_threads");`, { eval: true }))();
error: Uncaught (in worker "[worker eval]") (in promise) ReferenceError: require is not definedconst self = require("worker_threads"); ^ at data:text/javascript,const self = require("worker_threads");:1:14 info: Deno supports CommonJS modules in .cjs files, or when the closest package.json has a "type": "commonjs" option. hint: Rewrite this module to ESM, or change the file extension to .cjs, or add package.json next to the file with "type": "commonjs" option, or pass --unstable-detect-cjs flag to detect CommonJS when loading. docs: https://docs.deno.com/go/commonjs
error: Uncaught (in worker "[worker eval]") (in promise) ReferenceError: require is not definedconst self = require("worker_threads"); ^ at data:text/javascript,const self = require("worker_threads");:1:14 info: Deno supports CommonJS modules in .cjs files, or when the closest package.json has a "type": "commonjs" option. hint: Rewrite this module to ESM, or change the file extension to .cjs, or add package.json next to the file with "type": "commonjs" option, or pass --unstable-detect-cjs flag to detect CommonJS when loading. docs: https://docs.deno.com/go/commonjs
--unstable-detect-cjs
--unstable-detect-cjs
doesn't help. Deno 2.1.2
In my original project, the worker is in .cjs and imported from ESM but that doesn't seem to matter.
Only
import("node:worker_threads")
import("node:worker_threads")
works. But it is meant to support CJS. Also doesn't work without
node:
node:
which is not normal too but I assume both are related to one thing.