Repository navigation
Add find method to require #70
Description
Activity
- changed the title
[-]Add find method to require[/-][+]Add `find` method to require[/+]on Dec 4, 2014 Implementing this behaviour on your own is trivial:
function find( moduleName ){ try { return require.resolve( moduleName ); } catch( e ){ return null; } }
What exactly is
strangeabout it and why do you feel it is a wide enough issue that it deserves a new core API method?@missinglink Yep, it's trivial. And platform API should be clean and trivial, isn't? But the problem is that
requireis context-dependent function (it works different in each file). So it means that I should to implement find method in each file. It's not rational. And finally if there is way to do something without throwing an Error it should be done so.-1. The module loading code is
Stability: 5 - Lockedand unlikely to ever change.Just use @missinglink's snippet or the
optionalmodule.@fampinheiro Are you serious? Was you looking it's source? It will not work like it should because it not context-dependent and couldn't be.
@feross It's for node API. iojs will change loading code because it cannot use node_modules folder forever.Why can't it?
@aredridel Because iojs could not control Joyent policy so backward compatibility will be broken soon (after version 1.0). To prevent a mess of io and node packages module directory should be renamed.
Not sure why they'd be separate.
node_modulesis deeply baked in, and the module system is locked stability.and there's no guarantee that a breaking change will ever happen, nor would changing the folder name help that (it'd only break more)
@rumkin, @aredridel please stick to the reported issue and avoid speculation.
https://github.com/iojs/io.js/blob/v0.12/CONTRIBUTING.md#issue-contributions- added a commit that references this issue
on Feb 26, 2017 - added a commit that references this issue
on Apr 6, 2017 - added a commit that references this issue
on Apr 13, 2019 - added 2 commits that reference this issue
on Apr 27, 2021
Actually it's very strange behaviour of require.resolve, which throws an error when package not found. Add require.find method which would return null if package not found.