镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

require.resolve regression in Node v12 with paths #29139

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://github.com/proxy/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.

Activity

  1. cjihrig commented on Aug 15, 2019

    @cjihrig
    Contributor

    That [eval] bit seems suspect?

    I believe that's because your test script is launching node with -e to eval command line code.

    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.

    There was a bug that was fixed in the 12.0.0 release via #23683. I think that's what you're bumping into.

  2. FND commented on Aug 15, 2019

    @FND
    Author

    That all makes sense, thank you for the quick response!

  3. added a commit that references this issue on Aug 16, 2019
  4. added a commit that references this issue on Sep 2, 2019
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions