Skip to content

require.resolve() fails with an empty options objectΒ #28077

@75lb

Description

@75lb
  • Version: v12.4.0
  • Platform: macOS 10.14.5
  • Subsystem: module

In an empty directory, install lodash then from the REPL run the following commands. The second command fails if you pass an empty options object.

> require.resolve('lodash')
'/Users/lloyd/Documents/tmp/require-resolve/node_modules/lodash/lodash.js'

> require.resolve('lodash', {})
Thrown:
Error: Cannot find module 'lodash'
Require stack:
- <repl>
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.resolve (internal/modules/cjs/helpers.js:21:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}

If the options value is {} or { paths: undefined } I would expect it to be ignored and the built-in defaults used.

This issue breaks a few of my apps in node >= 12.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions