-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
importing a native library (e.g. node-tree-sitter) multiple in multiple test files results in a "TypeError: illegal invocation" #9206
Comments
@SimenB as you seem to be the most active developer lately, do you know what could be causing this behaviour? I would like to look for a fix and create a PR. Our only solution right now is to run each test file separately, which is slowing our tests down a lot. |
I have started debugging this and have found where the error is thrown when executing this line for the second time for the same native library: The error is caught by the try-catch on line 507 and says this: { stack: 'TypeError: Illegal invocation\n at Object.get [a…/node_modules/jest-runtime/build/index.js:433:10)',
message: 'Illegal invocation' } Where line 433 in the compiled Javascript is the following line: |
The error is actually thrown when the let binding;
try {
binding = require('./build/Release/tree_sitter_runtime_binding');
} catch (e) {
try {
binding = require('./build/Debug/tree_sitter_runtime_binding');
} catch (_) {
throw e;
}
}
const vm = require('vm');
const util = require('util')
const {Parser, NodeMethods, Tree, TreeCursor} = binding;
const {rootNode, edit} = Tree.prototype;
// ... It's the |
Removing the |
Can you put a |
@maxbrunsfeld I have been debugging yesterday and can confirm the I'm now looking into solving this issue by binding |
Binding the module which includes However, the actual project using this bug uses typescript. Fixing our code to conditionally import or use a global variable will make our code messier than we'd like. So we'll be switching testing framework. I've updated the example with the 'fix'. |
I am struggling with exactly the same issue and hope this will be fixed. |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
I am using node-tree-sitter in one of my projects. This library is in essence a thin layer wrapped around the tree-sitter binary (tree sitter is an incremental parser for multiple programming languages).
This library works fine, until I write tests for our program using. If two tests (indirectly) import the
tree-sitter
library, the second import sometimes fails withTypeError: illegal invocation
. Running each test separately doesn't exhibit this behaviour. Runningjest --clearCache
fixes this issue sometimes.However, I am unable to reproduce this bug outside Jest. When using ava I am able to re-import this library over 100 times without issues.
I have already submitted a bug report with the folks of
node-tree-sitter
. But because I am only encountering this bug with Jest, I'm thinking there could be going something wrong at Jest's side.To Reproduce
Steps to reproduce the behavior:
Expected behavior
Re-importing the library works just fine.
Link to repl or repo (highly encouraged)
https://github.com/rien/node-tree-sitter-bug-minimal-reproducible-example/
envinfo
The text was updated successfully, but these errors were encountered: