Skip to content

const beavior when erroring to set a module #16520

@luislobo

Description

@luislobo

I normally use the repl, to test out modules before actually using them.

Today I run into an issue that I don't really know if it's an issue or a "feature".

node                                                                                                                                                                                                                                                                                                                       ⬡ 8.7.0 ◇ 5.5.1  [±PETRO-797-guidon-export ●]
> const m = require('invalid-module-name-goes-here')
Error: Cannot find module 'invalid-module-name-goes-here'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at repl:1:11
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:440:10)
> const m = require('invalid-module-name-goes-here')
SyntaxError: Identifier 'm' has already been declared

> m
ReferenceError: m is not defined
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:440:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.Interface._line (readline.js:631:8)
> 
(To exit, press ^C again or type .exit)
> 

So, basically, you require a non existent module, assigning it to a const identifier. Then, when you try to redefine it (may be typing the correct module name, it doesn't matter much) it says it has been already declared, but after inspecting it, it says it's not defined.

So, weather the last reference error is wrong, saying it's not defined. Or may be there is a slight difference between defined and declared?

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateIssues and PRs that are duplicates of other issues or PRs.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