Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import mdns from a Worker #258

Open
bguezzie opened this issue Oct 4, 2022 · 5 comments
Open

Cannot import mdns from a Worker #258

bguezzie opened this issue Oct 4, 2022 · 5 comments

Comments

@bguezzie
Copy link

bguezzie commented Oct 4, 2022

I am trying to use mdns from inside of a Node.js Worker, but when I do I get the following error:
Module did not self-register: '/<...snipped...>/node_modules/mdns/build/Release/dns_sd_bindings.node'.

The import statement (written in TypeScript) is:
import mdns, {Browser, Service} from "mdns";

When I do this from the main thread, it works like a charm. I have done all the usual npm/node_modules tricks online trying to resolve and/or rebuild the library, but no dice.

OS: MacOS 12.5.1
Node: 18.9.0
mdns: 2.7.2

Please let me know what other information would be helpful here.

@bguezzie
Copy link
Author

bguezzie commented Oct 4, 2022

For what it's worth, I have isolated the error as arising from the import statement itself (a simple console log statement afterward never gets executed).

@bguezzie
Copy link
Author

bguezzie commented Oct 4, 2022

Here's the associated stack trace (sorry I forgot it earlier):

    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1203:18)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Function.Module._load (node:internal/modules/cjs/loader:838:12)
    at Module.require (node:internal/modules/cjs/loader:1021:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/<...snipped...>/node_modules/mdns/lib/dns_sd.js:24:20)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Object.require.extensions.<computed> [as .js] (/<...snipped...>/node_modules/ts-node/src/index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:997:32)

@bguezzie
Copy link
Author

bguezzie commented Oct 5, 2022

In case it helps, here's what the TS compiles to:

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_worker_threads_1 = require("node:worker_threads");
console.log('WONK: About to import...');  // <-- this is output
const mdns_1 = __importDefault(require("mdns"));
console.log(`WONK: ${mdns_1.default.tcp('foo')}`);  // <-- never gets here

@bguezzie
Copy link
Author

bguezzie commented Oct 5, 2022

Another interesting data point: Our project had been importing the module in the main thread (creating an Advertisement) as well as in the worker thread. When I comment out the import from the main thread and stub out the calls, the import works in the worker thread (tested a few times now without any error...I see both the log message before and after the import).

@agnat
Copy link
Owner

agnat commented Nov 24, 2022

Hi @bguezzie,
thanks for reporting this. Could you do me a favour and provide a pure javascript minimal reproducer? Just a single file (or block of code) that launches a worker and fails on require(...) demonstrating the issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants