Skip to content

REPL crash when specifying let or var #59029

@TheDevYellowy

Description

@TheDevYellowy

Version

v24.4.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

REPL

What steps will reproduce the bug?

Launch powershell and type "node" to open the REPL, then type "let" and any letter after that will initiate the crash

2025-07-11_00-37-27.mp4

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior? Why is that the expected behavior?

The repl doesn't crash and allows variable declaration

What do you see instead?

The repl crashes with the following error

node:internal/readline/emitKeypressEvents:74
            throw err;
            ^

TypeError: Cannot read properties of null (reading 'start')
    at findExpressionCompleteTarget (node:repl:1722:68)
    at REPLServer.complete (node:repl:1487:55)
    at REPLServer.completer (node:repl:792:5)
    at showCompletionPreview (node:internal/repl/utils:233:10)
    at showPreview (node:internal/repl/utils:389:7)
    at REPLServer.self._ttyWrite (node:repl:1037:9)
    at ReadStream.onkeypress (node:internal/readline/interface:284:20)
    at ReadStream.emit (node:events:507:28)
    at ReadStream.emit (node:domain:489:12)
    at emitKeys (node:internal/readline/utils:371:14)

Additional information

It seems like the following code is responsible for the crash, somehow lastDeclarationInit is null. If it helps at all I downloaded node via fnm

node/lib/repl.js

Lines 1718 to 1724 in 5576dec

// If the last statement is a variable declaration statement the last declaration is
// what we can potentially complete on, so let's re-run the function's logic on that
if (lastBodyStatement.type === 'VariableDeclaration') {
const lastDeclarationInit = lastBodyStatement.declarations.at(-1).init;
const lastDeclarationInitCode = code.slice(lastDeclarationInit.start, lastDeclarationInit.end);
return findExpressionCompleteTarget(lastDeclarationInitCode);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions