'How to import a local grammar in tree-sitter node?

I am currently trying to import my own created grammar in a typescript node project in the following way:

import Parser = require('tree-sitter');
import Language = require('tree-sitter-own');

This throws the error:

Cannot find module 'tree-sitter-own' or its corresponding type declarations.

In the package file under dependencies it is imported as follows:

"dependencies": {
        "tree-sitter-own": "file:../../tree-sitter-own"
}

If I check the node_modules folder it got correctly installed and copied over. There are however no type definition files in the tree-sitter grammar. How can you correctly import a grammar in node or how can you correctly add type declarations so typescript can use it?



Solution 1:[1]

Try to build your grammar using WASM and then require it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Konstantin Kim