oven-sh / bun

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

The module 'webgl' was compiled against a different Node.js ABI version using NODE_MODULE_VERSION 115. This version of Bun requires NODE_MODULE_VERSION 127. Please try re-compiling or re-installing the module. #14105

Open PrinOrange opened 1 week ago

PrinOrange commented 1 week ago

What version of Bun is running?

1.1.30

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

First, install the GPU.JS

bun install gpu.js

And run this sample code

import { GPU } from 'gpu.js';

// This is a program for executing matrix multiplication with GPU.JS

const gpu = new GPU();

const multiplyMatrix = gpu.createKernel(function(a: number[][], b: number[][]) {
  let sum = 0;
  for (let i = 0; i < 512; i++) {
    sum += a[this.thread.y][i] * b[i][this.thread.x];
  }
  return sum;
}).setOutput([512, 512]);

const matrixA = Array.from({ length: 512 }, () => Array.from({ length: 512 }, () => Math.random()));
const matrixB = Array.from({ length: 512 }, () => Array.from({ length: 512 }, () => Math.random()));

const result = multiplyMatrix(matrixA, matrixB);

console.log(result);

Then the program crashed.

What is the expected behavior?

It should do utmost compatible for running program like what node.js does. The above code works in node.js, but crashes in bun

What do you see instead?

It throws such error information,

PS E:\frontend-projects\gpu-js> bun run index.ts
107 |         return opts[p] || p;
108 |       })
109 |     );
110 |     tries.push(n);
111 |     try {
112 |       b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
                                                     ^
error: The module 'webgl' was compiled against a different Node.js ABI version using NODE_MODULE_VERSION 115. 
This version of Bun requires NODE_MODULE_VERSION 127. Please try re-compiling or re-installing the module.
      at bindings (E:\frontend-projects\gpu-js\node_modules\bindings\bindings.js:112:48)
      at E:\frontend-projects\gpu-js\node_modules\gl\src\javascript\native-gl.js:1:7
      at E:\frontend-projects\gpu-js\node_modules\gl\src\javascript\webgl-rendering-context.js:4:42
      at E:\frontend-projects\gpu-js\node_modules\gl\src\javascript\node-index.js:3:32
      at E:\frontend-projects\gpu-js\node_modules\gl\index.js:4:10
      at E:\frontend-projects\gpu-js\node_modules\gpu.js\src\backend\headless-gl\kernel.js:1:7
      at E:\frontend-projects\gpu-js\node_modules\gpu.js\src\gpu.js:5:9
      at E:\frontend-projects\gpu-js\node_modules\gpu.js\src\index.js:1:9

Bun v1.1.30-canary.27+d05070dbf (Windows x64)

Additional information

No response

birkskyum commented 6 days ago

When I've accounted this issue, I've generally had to go into node_modules/gl and run npm install --build-from-source.

190n commented 6 days ago

This is related to V8 API support. The reason you see that issue is that you have an older version of Node.js installed, which is different than the version that Bun pretends to be for V8 modules (currently 22.6.0), so the native module got compiled for an old version of Node.js and Bun won't be compatible with it.

This needs to be fixed, probably somewhere in bun install so that it builds against the correct version of Node.js. You can try to work around the issue by installing dependencies with the environment variable npm_config_target=v22.6.0 set (this tells node-gyp which version of Node.js to compile for):

$env:npm_config_target = 'v22.6.0';
bun install

However, if you do that you'll probably just run into a different issue because Bun still doesn't support very much of the V8 API. You can track support in issue #4290.