Skip to content

When core modules are shadowed, behavior differs from require.resolve #147

Closed
@searls

Description

@searls

@albertogasparin opened testdouble/quibble#22 which led me to this realization: if a core module (say, util) is shadowed by an npm package of the same name (say, util), then the behavior of this module will differ from the behavior of require.resolve in Node-core.

If attempting to load the shadowed package (as on would with require('util/')), the two functions are in agreement:

> require.resolve('util/')
'/Users/……/node_modules/util/util.js'
> resolve.sync('util/')
'/Users/……/node_modules/util/util.js'

But subsequent attempts to resolve the core module with plain ol' 'util' will differ:

> require.resolve('util')
'util'
> resolve.sync('util')
'/Users/……/node_modules/util/util.js'

(To pre-empt any request I simply use require.resolve(), I'm currently using this package for its preserveSymlinks option which Node's function lacks and which I've proposed be added here)

Eager to hear your thoughts on this and whether you'd consider this behavior to be a bug and advise how we should proceed or could help

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