Comments (10)
Implementing this behaviour on your own is trivial:
function find( moduleName ){
try {
return require.resolve( moduleName );
} catch( e ){
return null;
}
}
What exactly is strange
about it and why do you feel it is a wide enough issue that it deserves a new core API method?
from node.
@missinglink Yep, it's trivial. And platform API should be clean and trivial, isn't? But the problem is that require
is 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.
from node.
@rumkin you can use a module like optional if you don't want to wrap your require
s.
from node.
-1. The module loading code is Stability: 5 - Locked
and unlikely to ever change.
Just use @missinglink's snippet or the optional
module.
from node.
@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.
from node.
Why can't it?
from node.
@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.
from node.
Not sure why they'd be separate. node_modules
is 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)
from node.
@rumkin, @aredridel please stick to the reported issue and avoid speculation.
https://github.com/iojs/io.js/blob/v0.12/CONTRIBUTING.md#issue-contributions
from node.
I don't think this will change in the near future:
- It would expand the surface area of a locked subsystem.
- This behavior can be approximated in userland (and there exist packages to make that easier!)
Closing for now.
from node.
Related Issues (20)
- Inspector not starting with --watch flag before HOT 2
- [22 regression] Infinite recursion when setting `stat.atime` HOT 4
- [22 regression] Breaks gulp with `Cannot assign to read only property 'atime' of object '#<Stats>'` HOT 3
- Expose `process.env.NODE_OPTIONS` parser to user land HOT 2
- v22.0.0 breaks --v8-lite-mode build missing action for js-to-wasm-tq-csa.cc HOT 2
- Is `vcbuild` really needed
- `vm`: `constants` is undefined HOT 4
- Allow bailing early when test fails HOT 8
- Inconsistent presence of property in contextified object HOT 3
- Watch does not debounce restart when different files are updated within the debounce period
- gyp ERR! stack RangeError: Maximum call stack size exceeded HOT 8
- Could we support `corepack enable --yes`?
- `Reflect.has` triggers getters on global object contextified by `vm` HOT 3
- node --run doesn't split additional params HOT 3
- feat(doc): Add warning blocks to API docs
- Mybots
- npm not installing along with node 22.0.0. HOT 2
- fs.glob add option to only include files (not directories) in the results entries HOT 4
- Re-enable test-ubsan.yml
- Compiler error running on Node 20.12 (works in 20.11.6) in napi-intl.h when calling napi_status napi_create_external_buffer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node.