-
-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When core modules are shadowed, behavior differs from require.resolve
#147
Comments
require.resolve
require.resolve
I believe this might be related to nodejs/node#15015 I also suspect this is how browserify resolves some of its native module shims, such that changing this behavior might break it. What’s your use case for ever shadowing core modules? |
Understood. I'm not very familiar with browserify internals at all, so I'm curious if you can see any path forward in reconciling this.
Who knows man, I'm just a middle-man lib maintainer trying to identify the root cause of the aforementioned bug report ( testdouble/quibble#22 ), which mentioned that the reliance on the |
I found the bug while doing unit tests. I'm using |
It'd be useful to prepare a PR that "fixes" this behavior, so we can take a look at the tests. I agree that |
Given 'util' as an example native module which is also installed as an npm package, then in order for browserify/resolve to act consistently with native `require.resolve`, these should be true: ``` resolve.sync('util') // returns 'util' resolve.sync('util/') // returns 'node_modules/util/index.js' ```
Given 'util' as an example native module which is also installed as an npm package, then in order for browserify/resolve to act consistently with native `require.resolve`, these should be true: ``` resolve.sync('util') // returns 'util' resolve.sync('util/') // returns 'node_modules/util/index.js' ```
Given 'util' as an example native module which is also installed as an npm package, then in order for browserify/resolve to act consistently with native `require.resolve`, these should be true: ``` resolve.sync('util') // returns 'util' resolve.sync('util/') // returns 'node_modules/util/index.js' ```
Given 'util' as an example native module which is also installed as an npm package, then in order for browserify/resolve to act consistently with native `require.resolve`, these should be true: ``` resolve.sync('util') // returns 'util' resolve.sync('util/') // returns 'node_modules/util/index.js' ```
Given 'util' as an example native module which is also installed as an npm package, then in order for browserify/resolve to act consistently with native `require.resolve`, these should be true: ``` resolve.sync('util') // returns 'util' resolve.sync('util/') // returns 'node_modules/util/index.js' ```
@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 ofrequire.resolve
in Node-core.If attempting to load the shadowed package (as on would with
require('util/')
), the two functions are in agreement:But subsequent attempts to resolve the core module with plain ol'
'util'
will differ:(To pre-empt any request I simply use
require.resolve()
, I'm currently using this package for itspreserveSymlinks
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
The text was updated successfully, but these errors were encountered: