Skip to content

A way to forget a variable in Node.js REPL? #56752

Closed as duplicate
Closed as duplicate

Description

@geeksilva97

What is the problem this feature will solve?

It's just a tiny improvement for the REPL.

Take the following sample of REPL usage when a typo happened.

> const { DatabaseSync } = require('node:sqliite');
Uncaught Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: node:sqliite
    at Function._load (node:internal/modules/cjs/loader:1068:13)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16) {
  code: 'ERR_UNKNOWN_BUILTIN_MODULE'
}
> const { DatabaseSync } = require('node:sqlite');
Uncaught SyntaxError: Identifier 'DatabaseSync' has already been declared

Note that due to a typo, I can't use require again to import DatabaseSync. Instead, I usually close and open the reply.

What is the feature you are proposing to solve the problem?

Implementing a way to forget a variable would solve it.

The Erlang programming language doesn't allow reassignment, so a situation like the one described above might occur. To solve this, they have a utility function for forgetting a variable.

In the example below we can reuse Message after calling f(Message).

Image

NOTE: That would be good. However, I don't know of a way to do this in the current REPL. Please let me know if there's one.

What alternatives have you considered?

Using let when importing in REPL :)

Activity

  1. added
    feature request
    on Jan 24, 2025
  2. bnoordhuis commented on Feb 3, 2025

    @bnoordhuis
    Member

    See #8309 (comment) - tl;dr known issue that is fixable but requires a lot of work and no one (to my knowledge) has stepped up so far.

    Since this is a duplicate of an existing bug report, I'll go ahead and close it out.

  3. added
    duplicate
    on Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicatefeature request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions