Skip to content

TypeError: Cannot read properties of undefined (reading 'length') when using tree-sitter-elm with tree-sitter 0.21 #186

@ymtszw

Description

@ymtszw

Problem

As per tree-sitter's official usage, we should be able to initialize tree-sitter Parser with Elm language:

const Parser = require('tree-sitter');
const Elm = require('tree-sitter-elm');

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

However, with tree-sitter-elm 5.8.0 (which declares peerDependencies for tree-sitter ^0.21.1), the above code crashes:

/Users/yumatsuzawa/workspace/setem/node_modules/tree-sitter/index.js:837
  for (let id = 0, n = nodeTypeNamesById.length; id < n; id++) {
                                         ^

TypeError: Cannot read properties of undefined (reading 'length')
    at initializeLanguageNodeClasses (/Users/yumatsuzawa/workspace/setem/node_modules/tree-sitter/index.js:837:42)
    at Parser.setLanguage (/Users/yumatsuzawa/workspace/setem/node_modules/tree-sitter/index.js:342:5)
    at Object.<anonymous> (/Users/yumatsuzawa/workspace/setem/src/index.js:41:8)
    at Module._compile (node:internal/modules/cjs/loader:1554:14)
    at Object..js (node:internal/modules/cjs/loader:1706:10)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Module.require (node:internal/modules/cjs/loader:1311:12)

The probem was found on rountine package upgrade of my setem tool, which uses tree-sitter-elm (BTW, thanks a lot for this!)

https://github.com/ymtszw/setem/blob/master/src/index.js#L40-L41

The code was working fine with tree-sitter-elm 5.7.0 and tree-sitter 0.20.6

Environment

  • tree-sitter-elm 5.8.0
  • tree-sitter 0.21.1
  • Node.js 22.14.0
  • npm 11.2.0

Remarks

I wish I could have looked into it deeper myself, but I'm not familiar with the anatomy of tree-sitter, so it was tough. Let me know if there's any information you need from me!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions