Skip to content
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

Error: dlopen: symbol not found in flat namespace (_tree_sitter_kotlin_external_scanner_create) #120

Open
jennycai0807 opened this issue May 11, 2024 · 8 comments
Labels
bug Something isn't working scanner Related to the external scanner

Comments

@jennycai0807
Copy link

Error message:
node:internal/modules/cjs/loader:1452
return process.dlopen(module, path.toNamespacedPath(filename));
^

Error: dlopen(/Users/jenny.cai/Source/detect-bug-in-code/node_modules/tree-sitter-kotlin/build/Release/tree_sitter_kotlin_binding.node, 0x0001): symbol not found in flat namespace (_tree_sitter_kotlin_external_scanner_create)
at Module._extensions..node (node:internal/modules/cjs/loader:1452:18)
at Module.load (node:internal/modules/cjs/loader:1197:32)
at Module._load (node:internal/modules/cjs/loader:1013:12)
at Module.require (node:internal/modules/cjs/loader:1225:19)
at require (node:internal/modules/helpers:177:18)
at load (/Users/jenny.cai/Source/detect-bug-in-code/node_modules/node-gyp-build/node-gyp-build.js:22:10)
at Object. (/Users/jenny.cai/Source/detect-bug-in-code/node_modules/tree-sitter-kotlin/bindings/node/index.js:3:43)
at Module._compile (node:internal/modules/cjs/loader:1356:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
at Module.load (node:internal/modules/cjs/loader:1197:32) {
code: 'ERR_DLOPEN_FAILED'
}

Version:
"tree-sitter": "^0.21.1",
"tree-sitter-javascript": "^0.21.1",
"tree-sitter-typescript": "^0.21.1",
"tree-sitter-java": "^0.21.0",
"tree-sitter-kotlin": "^0.3.6",
"tree-sitter-swift": "^0.3.6",
"tree-sitter-cpp": "^0.22.0",
"tree-sitter-html": "0.20.3"

@VladimirMakaev
Copy link
Collaborator

@jennycai0807 Can you please provide a full repro command and OS you're using?

@jennycai0807
Copy link
Author

@VladimirMakaev
command:
const languageParsers = {
javascript: require('tree-sitter-javascript'),
typescript: require('tree-sitter-typescript').typescript,
tsx: require('tree-sitter-typescript').tsx,
java: require('tree-sitter-java'),
swift: require('tree-sitter-swift'),
kotlin: require('tree-sitter-kotlin'),
cpp: require('tree-sitter-cpp'),
html: require('tree-sitter-html')
};

// Function to create and set the language for the parser
function setLanguage(parser, language) {
const languageParser = languageParsers[language];
if (languageParser) {
parser.setLanguage(languageParser);
} else {
console.error(Unsupported language: ${language});
}
}

const parser = new Parser();
setLanguage(parser, language);
console.log(Code language:${language});

// parse code
const tree = parser.parse(code);
lines = code.split(/\n/);

OS: Mac 12.6.1

@VladimirMakaev
Copy link
Collaborator

I appreciate the repro but how do I execute this? Do I save this to a js file and run node? Probably not.

@jennycai0807
Copy link
Author

jennycai0807 commented May 30, 2024

@VladimirMakaev
Here is the js project. You can download and unzip.
tree-sitter-debug.zip

The repro command is:
npm install
node tree-sitter-test.js

@jennycai0807
Copy link
Author

Hi @VladimirMakaev Is there a workaround to skip this error? It blocks my process.

@VladimirMakaev
Copy link
Collaborator

I'm not sure. If you have a way to check this from sources try if this still breaks with this PR. #121

Otherwise you're welcome to figure this out and send a fix. I don't think anybody is currently looking specifically at fixing this.

Alternatively you can try bisecting to figure out where this broke and use a previous release

@ksrnnb
Copy link

ksrnnb commented Jun 21, 2024

I encountered the same error symbol not found in flat namespace '_tree_sitter_kotlin_external_scanner_create'.
My written code is below.

import { default as Parser } from "tree-sitter";
import language from "tree-sitter-kotlin";

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

versions

  • nodejs 18.19.1
  "dependencies": {
    "tree-sitter": "0.21.0",
    "tree-sitter-kotlin": "0.3.6"
  }

OS

  • MacBook Pro
  • Apple M2 Max
  • Sonoma 14.2.1

When I use tree-sitter-kotlin: 0.3.1 and tree-sitter: 0.20.6, I can avoid this error, but I want to use tree-sitter: >=0.21.0 because other packages like tree-sitter-go use it.
But when I use tree-sitter >= 0.21.0 and tree-sitter-kotlin: 0.3.1, I encountered another error below.

So, I have to use tree-sitter-kotlin: >= 0.3.2 but it throw an error symbol not found in flat namespace '_tree_sitter_kotlin_external_scanner_create'.

/Users/kyota/src/kotlin-error-test/node_modules/tree-sitter/index.js:338
    setLanguage.call(this, language);
                ^

TypeError: Invalid language object
    at Parser.setLanguage (/Users/kyota/src/kotlin-error-test/node_modules/tree-sitter/index.js:338:17)
    at file:///Users/kyota/src/kotlin-error-test/index.js:5:8
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12)

Node.js **v18.19.1**

And I tried #121 by defining dependencies as bellows, but I encountered an error symbol not found in flat namespace '_tree_sitter_kotlin_external_scanner_create'.

"dependencies": {
  "tree-sitter": "0.21.0",
  "tree-sitter-kotlin": "github:fwcd/tree-sitter-kotlin#7f6b43684536f9a7d26fb045bd79862e5710df9a"
}

@fwcd fwcd added scanner Related to the external scanner bug Something isn't working labels Jul 28, 2024
@cteyton
Copy link

cteyton commented Sep 5, 2024

Hi there,

I face a similar issue with Node 20.15.1 with the 0.3.6 package version.

I run this basic code:

const Parser = require('tree-sitter');
const Kotlin = require('tree-sitter-kotlin');

function checkSourceCode(sourceCode) {
  const parser = new Parser();
  parser.setLanguage(Kotlin);
  const tree = parser.parse(sourceCode);

}

checkSourceCode('fun main() {\n' +
    '    println("Hello, World!")\n' +
    '}');

I get this issue:

$ node kotlin.js 
node:internal/modules/cjs/loader:1454
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: /workspace/ai-agent-detection/js-playground/node_modules/tree-sitter-kotlin/build/Release/tree_sitter_kotlin_binding.node: undefined symbol: tree_sitter_kotlin_external_scanner_create
    at Module._extensions..node (node:internal/modules/cjs/loader:1454:18)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at load (/workspace/ai-agent-detection/js-playground/node_modules/node-gyp-build/node-gyp-build.js:22:10)
    at Object.<anonymous> (/workspace/ai-agent-detection/js-playground/node_modules/tree-sitter-kotlin/bindings/node/index.js:3:43)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v20.15.1

Hope that helps :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scanner Related to the external scanner
Projects
None yet
Development

No branches or pull requests

5 participants