Compatibility issues with `bun run` and `bun build --compile`
AI Policy
- I have read the AI Policy and this issue complies with it.
Problem
This commit f222db57cedb0836dc6297ac327076f2cbce93b0 introduced a regression for bun build --compile as it can't properly resolve the import paths at build time when a variable is used.
Furthermore plain bun run fails with the following error:
TypeError: To load Node-API modules, use require() or process.dlopen instead of import.
To fix both issues, we can check for the correct environment with Bun.isStandaloneExecutable and use ../.. instead of ${root}.
I already committed a fix in my own repo: dd144d5f025bd6545196ad2cd19eea1c3c3af787
Steps to reproduce
bun init ts-test
cd ts-test
bun i tree-sitter tree-sitter-c-sharp # this has the same bindings as this repoput this in index.ts:
import Parser from "tree-sitter";
import csharp from "tree-sitter-c-sharp";
const parser = new Parser();
parser.setLanguage(csharp);
const tree = parser.parse(`Console.WriteLine("Hello");`);
const root = tree.rootNode;
console.log(`root: ${root.type} [${root.startPosition.row}:${root.startPosition.column} - ${root.endPosition.row}:${root.endPosition.column}]`);
console.log(root.toString());bun run index.ts
bun build --compile index.ts && ./index
node index.tsboth bun commands will fail with:
TypeError: To load Node-API modules, use require() or process.dlopen instead of import.
node works
To test my patch it can be directly applied to node_modules/tree-sitter-c-sharp/bindings/node/index.js
Expected behavior
I expect it to work with bun too. My patch fixes that.
Tree-sitter version (tree-sitter --version)
tree-sitter 0.26.9
Operating system/version
GNU/Linux
Source: tree-sitter/tree-sitter