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)
- Minimatch dep update fails HOT 2
- ESLint dep update fails HOT 3
- assert: Assert will only check enumerable properties HOT 4
- parallel.test-crypto-rsa-dsa fails with `Missing expected exception` HOT 7
- unhandledRejection Error [ERR_INTERNAL_ASSERTION]: Code: ERR_MODULE_NOT_FOUND
- Clipboard Management in NodeJS HOT 4
- stream.finished docs are lacking
- Perf Issue with passing CA certs in Agent Options for HTTPS calls vs NODE_EXTRA_CA_CERTS
- flaky: parallel/test-http2-large-write-multiple-requests HOT 1
- Command run failed with error : spawn EINVAL HOT 14
- Request to upgrade libuv package to 1.47.0 or higher in node@20 HOT 4
- delete
- Migrate ESLint config to flat config
- NodeJS Crash AWS Lambda v20 HOT 6
- Getting EINVAL error on Windows upon NPM execution after node.js update to 20.12.2 HOT 4
- unhandledRejection Error [ERR_INTERNAL_ASSERTION] HOT 5
- Remove --experimental-policy HOT 24
- IORedis causing node internal issue HOT 2
- UNABLE_TO_VERIFY_LEAF_SIGNATURE/unable to verify the first certificate error HOT 3
- `fs.openAsBlob()` does not work properly for files > 2GB HOT 7
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.