-
Notifications
You must be signed in to change notification settings - Fork 11
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
Handle optional, environment-dependent native dependencies #15
Comments
Is it originally in try-catch clause? |
Original code in
Code in the bundled file
And further in the code, in method requireCrypto() so not top-level
|
So it looks like we're still doing this conditionally aren't we? |
Btw you may need to use |
Oopsie, I copy-pasted the code that's generated after I applied the band-aid (which is wrapping in a silent try/catch) I edited the previous message and the issue stays: A conditional require (wrapped in a try/catch, in a method) has been transformed into a top-level require which fails at runtime. I haven't had the time to tinker with |
I think that that's your solution. As not all modules are optional within a try-catch, it's not something that the current module should generate. It's handled by commonjs plugin. |
The more I play with rollup and the less I understand this issue :( Does it become an issue with the |
You don't want this require to be removed by commonjs, you want it to stay and inside try-catch :) |
Confusion around ignoreTryCatch was solved by a fix in the docs |
Thought process explained in greater detail here mscdex/ssh2#1201
Some of the native dependencies bundled by
rollup-plugin-natives
are optional, e.g. in the above example, when installing thessh2
module, the filessshcrypto.node
andcpu-features.node
may or may not be present depending on the environment installing the module (In that example, Windows has both, MacOS only has sshcrypto, and Unix has none, from what I could observe), and thessh2
module defaults to another behavior if the file cannot be found or read.But when bundling,
rollup-plugin-natives
writes an explicit requirevar sshcrypto = require('sshcrypto.node')
in the bundled js file, which fails at runtime if the file is not present.Workaround would be to wrap the require in a try/catch
e.g.
var sshcrypto;try{sshcrypto=require("./sshcrypto.node")}catch(err){};
The text was updated successfully, but these errors were encountered: