invalid require() should only throw an exception at runtime,
packager should not produce this error:
uncaught error Error: UnableToResolveError: Unable to resolve module foo from ...: Invalid directory ...
This breaks some NPM library to work, for instance: https://github.com/davidbau/seedrandom/issues/31
Hey gre, thanks for reporting this issue!
React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
react-native or for more real time interactions, ask on Discord in the #react-native channel.Not throwing errors at compile time will lead to more problems. Developers might not realize a problem without testing the whole app. A better approach might be the following, like in node,
let myLib;
try {
myLib = require('./some-module');
} catch (err) {
myLib = require('./similar-module');
}
There is something similar for browserify - https://www.npmjs.com/package/browserify-optional
What's the next actionable step for this issue?
cc @martinbigio , of course :)
As @satya164 mentioned, we want to fail hard at compile time if a dependency cannot be resolved. I think that if we want to support this use case we'll have to introduce a new transform similarly to what browserify does.
@gre thanks for bringing up this issue. We're going to close the issue out to keep our issues as focused as possible on bugs. A PR would be a good next step, or adding this on Product Pains. Feel free to continue discussion on the closed issue!
@martinbigio - I agree having a "require" should be fatal, due to the terminology, but wrapping it in a try/catch, pretty much means the user knew it was optional yes? This what node, does. Safe to say the user is well aware that the file may not be there.
If this continues to be an issue, and packager wants to be different from Node, then I say embrace being different and create a function like requiref, where a user is using a different function all-together that can be wrapped in a try/catch. Thoughts?
Any update on this? It would be handy for local configs that don't need to be committed & built by services such as Buddybuild.
Most helpful comment
Any update on this? It would be handy for local configs that don't need to be committed & built by services such as Buddybuild.