Skip to content

require.resolve regression in Node v12 with paths #29139

@FND

Description

@FND
  • Version: 12.8.0
  • Platform: Darwin v17.7.0 x86_64
  • Subsystem: modules (require.resolve)

related issue: #27794 - but that was fixed in v12.3.0

Given the following directory structure:

/path/to/lib
├── dummy
│   ├── index.js
│   └── src.js
└── node_modules
    └── dummy
        ├── index.js
        └── pkg.js

On Node v8, v10 and v11, the following returned /path/to/lib/dummy/src.js, but Node v12 (all minor/patch releases) throws a MODULE_NOT_FOUND exception ("Cannot find module 'dummy/src.js'"):

require.resolve("dummy/src.js", { paths: ["/path/to/lib"] });

(FWIW, I've automated bisecting Node versions: https://gist.github.com/FND/d35c5a5c128a7d0e9131ece904f601a9)

Node v12.8.0's stack trace looks interesting:

Require stack:
- /tmp/nodejs_versions/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:713:15)
    at Function.resolve (internal/modules/cjs/helpers.js:74:19)
    at [eval]:1:9
    at Script.runInThisContext (vm.js:126:20)
    at Object.runInThisContext (vm.js:316:38)
    at Object.<anonymous> ([eval]-wrapper:9:26)
    at Module._compile (internal/modules/cjs/loader.js:868:30)
    at evalScript (internal/process/execution.js:80:25)
    at internal/main/eval_string.js:23:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/tmp/nodejs_versions/[eval]' ]
}

That [eval] bit seems suspect?

Arguably v12's behavior is more correct (not sure why we expected /path/to/lib/dummy to be supported in the first place), but it's a behavioral change nonetheless. Since I couldn't find any relevant entries in Node's change log, I'm not sure whether this change was intentional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions