oven-sh / bun

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

tree-sitter undefined symbol: _ZN2v812BackingStore12EmptyDeleterEPvmS1_ #4188

Open LowByteFox opened 1 year ago

LowByteFox commented 1 year ago

What version of Bun is running?

0.7.4

What platform is your computer?

Linux 6.4.10-zen2-1-zen x86_64 unknown

What steps can reproduce the bug?

Create empty project, install both tree-sitter and tree-sitter-javascript with npm

type this into index.ts

const Parser = require('tree-sitter');
const JavaScript = require('tree-sitter-javascript');

const parser = new Parser();
parser.setLanguage(JavaScript);

const sourceCode = 'let x = 1; console.log(x);';
const tree = parser.parse(sourceCode);

console.log(tree.rootNode.toString());

run the file

What is the expected behavior?

When executed with node on index.cjs (program (lexical_declaration (variable_declarator name: (identifier) value: (number))) (expression_statement (call_expression function: (member_expression object: (identifier) property: (p roperty_identifier)) arguments: (arguments (identifier)))))

What do you see instead?

1 | (function (id){"use strict";var cached=@requireMap.@get(id);const last5=id.substring(id.length-5);if(cached)return cached.exports;if(last5===".json"){var fs=globalThis[Symbol.for("_fs")
]||=@Bun.fs(),exports=JSON.parse(fs.readFileSync(id,"utf8"));return @requireMap.@set(id,@createCommonJSModule(id,exports,!0)),exports}else if(last5===".node"){const module=@createCommonJSMo
dule(id,{},!0);return process.dlopen(module,id),@requireMap.@set(id,module),module.exports}else if(last5===".toml"){var fs=globalThis[Symbol.for("_fs")]||=@Bun.fs(),exports=@Bun.TOML.parse(
fs.readFileSync(id,"utf8"));return @requireMap.@set(id,@createCommonJSModule(id,exports,!0)),exports}else{var exports=@requireESM(id);const cachedModule=@requireMap.@get(id);if(cachedModule
)return cachedModule.exports;return @requireMap.@set(id,@createCommonJSModule(id,exports,!0)),exports}})
                       ^
TypeError: /home/jani/tests/node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node: undefined symbol: _ZN2v812BackingStore12EmptyDeleterEPvmS1_
      at internalRequire (:1:20)
      at /home/jani/tests/node_modules/tree-sitter/index.js:3:2
      at globalThis (/home/jani/tests/node_modules/tree-sitter/index.js:708:28)
      at require (:1:20)
      at /home/jani/tests/index.ts:1:6
      at globalThis (/home/jani/tests/index.ts:10:36)

Additional information

No response

vjpr commented 1 year ago

Also in 0.8.0 canary.

Maybe related, seems it hasn't been published in a while: https://github.com/tree-sitter/tree-sitter-typescript/issues/259

LowByteFox commented 1 year ago

ping?

sualehasif commented 1 year ago

this is one of 2+ blocking reasons we cant use bun :(

amaanq commented 1 year ago

As a core tree-sitter member, I also get this error. I am excited to try out using bun with tree-sitter, but I'm not that experienced in nodejs/js/ts/bun as I am in rust/c/c++

It is not an issue in tree-sitter-typescript, that's just a grammar repo. node-tree-sitter is the repo of interest if using the node.js bindings, or tree-sitter core for the wasm bindings

Gonna tack on that iirc bun does not play super well with v8-specific stuff, that could be the issue, I can provide anything to help debug this anyways

LowByteFox commented 1 year ago

Looking at the symbol, I can see v8 so it has to do something with it.

sualehasif commented 1 year ago

btw, i would love to help get this resolved. i know that in the short term, bun has no intention to implement the v8:: apis. maybe its worth rewriting this with napi.rs so that it can be used in bun?

amaanq commented 1 year ago

There is a plan to rewrite node-tree-sitter's binding using napi instead of nan, but that's a large-scale effort that has to be propagated upstream for downstream grammars will need to regenerate their bindings to leverage napi as well.

sualehasif commented 1 year ago

do you have an issue you can link to? wondering what the downstream grammar impacts are?

amaanq commented 1 year ago

relevant pr https://github.com/tree-sitter/node-tree-sitter/pull/52