Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Error: Requiring unknown module "stream". #1080

Closed
boby1975 opened this issue Apr 15, 2020 · 7 comments
Closed

Error: Requiring unknown module "stream". #1080

boby1975 opened this issue Apr 15, 2020 · 7 comments

Comments

@boby1975
Copy link

boby1975 commented Apr 15, 2020

Hi guys,
I use LiquidCore (Node.js virtual machine) inside my Android App. And I'm trying to use openpgp.js under Node. Here is my file example.js

console.log('Version: ' + JSON.stringify(process.versions));
try {
  var crypto = require('crypto');
  console.log('crypto support is enabled!');
} catch (error) {
  console.log('crypto support is disabled!');
  console.error(error.message);
}
try {
  var stream = require('stream');
  console.log('stream support is enabled!');
} catch (error) {
  console.log('stream support is disabled!');
  console.error(error.message);
}
const openpgp = require('./openpgp/openpgp.min.js');

and here is result

D/MicroService: User-Agent : LiquidCore/0.7.7 (Android; API 24)
I/stdout: Version: {"http_parser":"2.8.0","node":"10.15.3","v8":"6.8.275.32-node.51","uv":"1.23.2","zlib":"1.2.7","ares":"1.15.0","modules":"64","nghttp2":"1.34.0","napi":"3","openssl":"1.1.0j","icu":"62.1","unicode":"11.0","cldr":"33.1","tz":"2018e","liquidcore":"0.7.7"}
I/stdout: crypto support is enabled!
I/stdout: stream support is enabled!
E/JSEXCEPTION: Unhandled exception: Error: Requiring unknown module "stream".
    example.bundle.js:212
          throw e;
          ^
    
    Error: Requiring unknown module "stream".
        at unknownModuleError (example.bundle.js:218:12)
        at loadModuleImplementation (example.bundle.js:183:13)
        at guardedLoadModule (example.bundle.js:128:14)
        at metroRequire (example.bundle.js:65:132)
        at i (example.bundle.js:277:35)
        at example.bundle.js:287:22
        at Object.<anonymous> (example.bundle.js:12230:26)
        at Object.76.stream (example.bundle.js:12253:12)
        at i (example.bundle.js:286:21)
        at example.bundle.js:287:22
I/sessionWatchdog: deleting session /data/user/0/oko.org.ua.myapplication/cache/__org.liquidplayer.node__/sessions/e922ceac-5e34-4209-8827-c8c27d890174

Does anybody know why it happens? And how it can be fixed?
Thanks a lot

@twiss
Copy link
Member

twiss commented Apr 15, 2020

Hey 👋 It seems like you're trying to bundle OpenPGP.js as part of a larger example.bundle.js file, right? This is not supported, for now. Please see if you can convince your build system to treat OpenPGP.js as an external dependency, and require openpgp.min.js at runtime, instead of at build time.

@ArtemisKS
Copy link

Thx for an answer @twiss !

Please see if you can convince your build system to treat OpenPGP.js as an external dependency, and require openpgp.min.js at runtime, instead of at build time.

Can you maybe clarify a bit how that is possible, namely when using Webpack for bundling? Would be very grateful!

@twiss
Copy link
Member

twiss commented Apr 15, 2020

Hi @ArtemisKS 👋 Something like https://webpack.js.org/configuration/externals/ should work, I think.

For what it's worth, for the example above, you don't need a build system at all, and you can just run it as-is on Node.js, with OpenPGP.js in a separate file. But I do understand that for a larger example, this may not be the case.

@ArtemisKS
Copy link

ArtemisKS commented Apr 15, 2020

Thanks a lot for your answer, @twiss ! Unfortunately, it didn't work out, as we are trying to run OpenPGP on native mobile platforms (iOS & Android, swift & java respectively). Have been trying to use OpenPGP there with the help of LiquidCore, a virtual node env for mobile platforms. So far, it hasn't worked out, because of an aforementioned error, and errors like that (for iOS, it has been built, but throws exceptions when using OpenPGP methods, like readArmored). Besides, for iOS there's this native js virtual environment, JavaScriptCore, and I have thus far been unable to work with openpgp from there, although I did successfully so with other npm modules, such as thinbus-srp. Perhaps there's not much point in telling you all this, but maybe you can help us out with it, or else, give us your advice or manual on how to successfully run OpenPGP on mobile platforms. Thanks in advance!

@twiss
Copy link
Member

twiss commented Apr 15, 2020

So - it seems to have this automatic bundling thing: https://github.com/LiquidPlayer/LiquidCore#automatic-bundling. Are you using that? If so, I'm guessing you may be caught up by that.

Do you need bundling? I.e. do you have any dependencies other than OpenPGP.js that are cumbersome to copy to the output directory manually? If no, then the easiest may be to just not use bundling at all, and copy your scripts manually. Or, if you're already using your own bundling (using Webpack), you shouldn't need it either.

If you still want their bundling, you might have to convince Metro (the bundler they're using) to exclude OpenPGP.js. There are some hints of how to do that here: https://stackoverflow.com/a/41963217

@boby1975
Copy link
Author

boby1975 commented Apr 16, 2020

It seems like you're trying to bundle OpenPGP.js as part of a larger example.bundle.js file, right? This is not supported, for now.

You are right - OpenPGP.js is as part of a larger example.bundle.js file. Unfortunately I could not get openpgp.js outside of the bundle (as an external dependency) during apk building in Android Studio. And the file "metro.config.js" with "...blacklistRE: blacklist([/dist/.*/]" and other options didn't help me ... I'm not strong in JS (((
Сould you tell me why OpenPGP.js does not work in the bundle and what could be done to make it work there?
Thanks a lot.

@twiss
Copy link
Member

twiss commented Apr 16, 2020

Сould you tell me why OpenPGP.js does not work in the bundle and what could be done to make it work there?

OpenPGP.js has its own build system which is pretty complex, and for now, we only publish ready-made dist bundles. We would like to fix this, and make it possible to use an external build system, though: see #547, for example.

@twiss twiss closed this as completed Feb 9, 2021
@openpgpjs openpgpjs locked and limited conversation to collaborators Feb 9, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants