Skip to content

Self referential modules not supported in repl or -r #31595

@MylesBorins

Description

@MylesBorins

If you attempt to require('package-name') using v13.7.0 in the repl it will fail with a 'MODULE_NOT_FOUND' error.

// index.js
console.log('yay')
// package.json
{
  "name": "ohno",
  "main": "./index.js"
}
$ node
> require('ohno')

Uncaught Error: Cannot find module 'ohno'
Require stack:

  • at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15) at Function.Module._load (internal/modules/cjs/loader.js:862:27) at Module.require (internal/modules/cjs/loader.js:1040:19) at require (internal/modules/cjs/helpers.js:72:18) { code: 'MODULE_NOT_FOUND', requireStack: [ '' ]

}

$ node -r ./index.js
yay
$ node -r ohno

internal/modules/cjs/loader.js:983
throw err;
^

Error: Cannot find module 'ohno'
Require stack:

  • internal/preload
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at Module._preloadModules (internal/modules/cjs/loader.js:1296:12)
    at loadPreloadModules (internal/bootstrap/pre_execution.js:435:5)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:68:3)
    at internal/main/repl.js:18:1 {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ 'internal/preload' ]
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions