oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.52k stars 2.79k forks source link

TypeError: symbol 'napi_register_module_v1' not found in native module. #5578

Open robobun opened 1 year ago

robobun commented 1 year ago

Originally reported on Discord: Runningbun --hot server.tswith leveldb thro...

xhyrom commented 1 year ago

Using leveldb (after running postinstall) throws:

1 | (function (id) {"use strict";
                        ^
TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
      at internalRequire (:1:20)
      at load (/Users/codermickey/Development/buntest/node_modules/node-gyp-build/node-gyp-build.js:22:9)
      at /Users/codermickey/Development/buntest/node_modules/classic-level/binding.js:1:7
      at globalThis (/Users/codermickey/Development/buntest/node_modules/classic-level/binding.js:1:52)
      at require (:1:20)
      at /Users/codermickey/Development/buntest/node_modules/classic-level/index.js:7:6
      at globalThis (/Users/codermickey/Development/buntest/node_modules/classic-level/index.js:190:23)

consider renaming this issue

nicosammito commented 1 year ago

This is also very urgent for us.

SaltFish001 commented 1 year ago

when use bun with uWebSocket.js, i got same error.

./uws_linux_x64_115.node
18 | module.exports = (() => {
19 |    try {
20 |            console.log('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node')
21 |            return require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node');
22 |    } catch (e) {
23 |            throw new Error('This version of uWS.js supports only Node.js LTS versions 16, 18 and 20 on (glibc) Linux, macOS and Windows, on Tier 1 platforms (https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list).\n\n' + e.toString());
            ^
error: This version of uWS.js supports only Node.js LTS versions 16, 18 and 20 on (glibc) Linux, macOS and Windows, on Tier 1 platforms (https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list).

TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
      at /home/saltfish/Mems/Dummy/service/routesservice/node_modules/uWebSockets.js/uws.js:23:8
      at /home/saltfish/Mems/Dummy/service/routesservice/node_modules/uWebSockets.js/uws.js:23:239
      at globalThis (/home/saltfish/Mems/Dummy/service/routesservice/node_modules/uWebSockets.js/uws.js:25:3)
      at overridableRequire (:1:20)
      at /home/saltfish/Mems/Dummy/service/routesservice/dist/index.js:37336:20
      at /home/saltfish/Mems/Dummy/service/routesservice/dist/index.js:18:74
      at /home/saltfish/Mems/Dummy/service/routesservice/dist/index.js:40495:35
Electroid commented 11 months ago

Same issue when using ssh2

Screenshot 2023-12-24 at 5 00 37 PM
Yukie-Billal commented 7 months ago

Same issue using package bcrypt in typescript

Running env Bun version 1.1.0 OS windows 11

error-napi_register_module

0Charliecat commented 6 months ago

Same-ish issue using raspi-io

piserver@raspberrypi:~/elysia2/app $ bun run src/index.ts 
107 |         return opts[p] || p;
108 |       })
109 |     );
110 |     tries.push(n);
111 |     try {
112 |       b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
                                                     ^
TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
      at bindings (/home/piserver/elysia2/app/node_modules/bindings/bindings.js:112:48)
      at /home/piserver/elysia2/app/node_modules/pigpio/pigpio.js:6:7
      at /home/piserver/elysia2/app/node_modules/raspi-gpio/dist/index.js:27:7
      at /home/piserver/elysia2/app/node_modules/raspi-io/dist/index.js:30:7

Bun v1.1.9 (Linux arm64)
andeeplus commented 6 months ago

Same with "@parcel/watcher": "^2.4.0" while using --hot only.

│       at /Users/**/**/node_modules/@parcel/watcher/index.js:15:13
│ 10 |   }
│ 11 | }
│ 12 | 
│ 13 | let binding;
│ 14 | try {
│ 15 |   binding = require(name);
│                  ^
│ TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
│       at /Users/**/**/node_modules/@parcel/watcher/index.js:15:13

Edit

Just for the records it works with dynamic import const watcher = await import('@parcel/watcher');

mk0y commented 5 months ago

Did someone solve this? I'm getting the same error with bcrypt

1 | 'use strict';
2 | 
3 | var nodePreGyp = require('@mapbox/node-pre-gyp');
4 | var path = require('path');
5 | var binding_path = nodePreGyp.find(path.resolve(path.join(__dirname, './package.json')));
6 | var bindings = require(binding_path);
                   ^
TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
      at /Users/.../api/node_modules/bcrypt/bcrypt.js:6:16

EDIT: I found out that we don't even need bcrypt with Bun: https://bun.sh/guides/util/hash-a-password This is enough for us.

tresabhi commented 5 months ago

If you were using lz4 like me, switch to lz4js. API is a little different and uses Uint8Array instead of Buffer but that's totally acceptable.

Yash-Singh1 commented 3 months ago

I can reproduce this when using node:worker_threads.Worker instead of the Bun global worker for requiring a .node file.

Works:

const blob = new Blob(  [`require('./node_modules/rocksdb/prebuilds/darwin-x64+arm64/node.napi.node')`, ],{type: "application/typescript",},);
const blobURL = URL.createObjectURL(blob);
const worker = new Worker(blobURL);

Doesn't work:

const blob = new Blob(  [`require('./node_modules/rocksdb/prebuilds/darwin-x64+arm64/node.napi.node')`, ],{type: "application/typescript",},);
const blobURL = URL.createObjectURL(blob);
const worker = new (require('node:worker_threads').Worker)(blobURL);

error:

> 184 |   postMessage(...args) {
185 |     return this.#worker.postMessage(...args);
186 |   }
187 |   #onClose(e) {
188 |     this.#onExitPromise = e.code, this.emit("exit", e.code);
189 |   #onError(event) {
                ^
error: 1 | require('./node_modules/rocksdb/prebuilds/darwin-x64+arm64/node.napi.node')
    ^
TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
harveylee commented 2 months ago

Same error with @project-osrm/osrm:

TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?
      at /home/xxx/node_modules/@project-osrm/osrm/lib/index.js:1:19
r-rajaneesh commented 2 months ago

Same error when using zlib-sync https://npmjs.com/package/zlib-sync image