Install & Compatibility
Where this runs
tested against v0.25.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.052s · 19.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.046s · 21MB
18MB installed
● package 18MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
language
✓ from tree_sitter_javascript import language
This quickstart demonstrates how to load the JavaScript grammar, create a parser, and parse a simple JavaScript code snippet. It then shows how to access the root node and find a specific node type, such as a function declaration, illustrating basic tree traversal.
import tree_sitter
from tree_sitter_javascript import language
# 1. Get the JavaScript language object
JS_LANGUAGE = language()
# 2. Create a parser and set the language
parser = tree_sitter.Parser()
parser.set_language(JS_LANGUAGE)
# 3. Parse some JavaScript code (must be bytes)
code = b"""
function greet(name) {
console.log("Hello, " + name + "!");
}
greet("World");
"""
tree = parser.parse(code)
# 4. Access the root node and explore the tree
root_node = tree.root_node
print(f"Root node type: {root_node.type}")
print(f"Root node content (first 50 chars): {root_node.text.decode('utf8')[:50]}...")
# Example: Find the 'function_declaration' node
function_node = None
for child in root_node.children:
if child.type == 'function_declaration':
function_node = child
break
if function_node:
function_name_node = function_node.child_by_field_name('name')
if function_name_node:
print(f"Found function name: {function_name_node.text.decode('utf8')}")
Debug
Known issues
gotchaThe `tree-sitter-javascript` package *provides* the grammar, but it inherently depends on the core `tree-sitter` Python library to function. Many users forget to install `tree-sitter` alongside this grammar package, leading to `ModuleNotFoundError` for `tree_sitter` or issues when trying to instantiate `Parser` objects. Always install both.fixEnsure you install both `tree-sitter-javascript` and `tree-sitter`: `pip install tree-sitter-javascript tree-sitter`.
affects: All versions
gotchaThe underlying `tree-sitter` core library (which `tree-sitter-javascript` leverages) is a C extension. While pre-built wheels are available for many common platforms, certain environments (e.g., specific Linux distributions, custom Python builds, or older Python versions) may require a C compiler (like GCC or Clang) during installation. Lack of a compiler can cause installation failures.fixEnsure a C compiler is installed and available in your environment before attempting installation. For Debian/Ubuntu: `apt-get install build-essential`. For macOS: `xcode-select --install`.
affects: All versions
breakingWhile the `language()` function provided by `tree-sitter-javascript` is generally stable, major version changes in the upstream `tree-sitter` Python library can introduce breaking API changes for `Parser`, `Tree`, or `Node` objects. Similarly, significant updates to the underlying JavaScript grammar definition (less frequent for the Python binding) could subtly change the structure of the generated ASTs.fixIt is strongly recommended to pin both the `tree-sitter-javascript` and `tree-sitter` package versions in your `requirements.txt` or project dependencies to ensure consistent behavior across deployments (e.g., `tree-sitter-javascript==0.25.0`, `tree-sitter==0.21.1`).
affects: All versions, especially across major `tree-sitter` updates.
Upgrade
Version history
0.25.0latest on PyPI · released Sep 1, 2025
Audit
Dependencies
tree-sitterrequiredThe core Python `tree-sitter` library is required to create parsers and interact with the grammar.