Uncaught `ast.resolveStack is not a function` when using C/Java language modes breaks autoindent

I have the following basic editor:

import { EditorView, keymap, drawSelection } from '@codemirror/view'
import { indentUnit } from '@codemirror/language'
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands'
import { java } from '@codemirror/lang-java'

export const basicSetup = [
  indentUnit.of('    '),

const editor = new EditorView({
  extensions: [basicSetup, java()],
  parent: document.getElementById('editor'),
  doc: 'class HelloWorld {\n  public static void main(String[] args) {\n    System.out.println("Hello, World!");\n  }\n}'

When I press enter in an indented block, such as the one with System.out.println(), an uncaught exception stating ast.resolveStack is not a function is logged with the following stack trace:

TypeError: ast.resolveStack is not a function
at syntaxIndentation (@codemirror+language@6.10.1/node_modules/@codemirror/language/dist/index.js)
at getIndentation (@codemirror+language@6.10.1/node_modules/@codemirror/language/dist/index.js)

The same issue can be seen in @codemirror/lang-cpp, but not in other language modes like @codemirror/lang-javascript, or if I remove the language modes entirely from my code.

Further, the code snippet above used to work with older versions of codemirror.

Am I doing something wrong in the above snippet and how can I fix it?


You somehow got stuck with an old version of @lezer/common, though dependency declarations should be requesting a newer one. Try clearing your package lock and/or node_modules and reinstalling dependencies.

1 Like