Skip to content

Native NAPI module cannot be required only in a Worker thread #19339

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

Open
toverux opened this issue Apr 28, 2025 · 0 comments
Open

Native NAPI module cannot be required only in a Worker thread #19339

toverux opened this issue Apr 28, 2025 · 0 comments
Labels
bug Something isn't working napi Compatibility with the native layer of Node.js Worker uses the web or node worker api

Comments

@toverux
Copy link

toverux commented Apr 28, 2025

What version of Bun is running?

1.2.10+db2e7d7f7

What platform is your computer?

Linux 6.14.0-15-generic x86_64 x86_64

What steps can reproduce the bug?

In any file, import:

import '@tensorflow/tfjs-node';

This works perfectly in the main thread.
Now try this in a Worker, and you will get a crash (limited to the worker and recoverable).

What is the expected behavior?

No crash when importing a native module.

What do you see instead?

The same import in a Worker file has less success:

67 |         "the addon module, please check " +
68 |         "https://github.com/tensorflow/tfjs/blob/master/tfjs-node/" +
69 |         "WINDOWS_TROUBLESHOOTING.md or file an issue.");
70 | }
71 | // tslint:disable-next-line:no-require-imports
72 | var bindings = require(bindingPath);
                    ^
TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
      at <anonymous> (/node_modules/@tensorflow/tfjs-node/dist/index.js:72:16)

Additional information

This might be related to #4290, however since this issue does not mention workers, and since it works fine unless running in a worker, I thought it might be a separate issue and hopefully a low-hanging fruit.

Edit: the same problem was reported here #5578 (comment) but the Issue was closed in favor of the aforementioned one, but since this is a particular issue with workers I think we could have a dedicated issue.

@toverux toverux added bug Something isn't working needs triage labels Apr 28, 2025
@toverux toverux changed the title Native NAPI module not working only in a Worker thread Native NAPI module cannot be required only in a Worker thread Apr 28, 2025
@RiskyMH RiskyMH added napi Compatibility with the native layer of Node.js Worker uses the web or node worker api and removed needs triage labels Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working napi Compatibility with the native layer of Node.js Worker uses the web or node worker api
Projects
None yet
Development

No branches or pull requests

2 participants