Skip to content
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

Node flag "--experimental-require-module" isn't actually used by NW.js #8237

Open
vankasteelj opened this issue Nov 23, 2024 · 1 comment
Open

Comments

@vankasteelj
Copy link

vankasteelj commented Nov 23, 2024

Issue Type

  • Bug Report
  • Was successfully reproduced against the latest version of NW.js

Current/Missing Behavior

the node>22.x flag --experimental-require-module can't seem to be used on NW.js .

Using either in package.json:
"node-main": "--experimental-require-module"
Or with the CLI ./nw.exe --experimental-require-module

The error thrown when require() is used in the app is require() of ES Module. Using the same flag with node (and not NWjs!!) gives the error require() cannot be used on an ESM graph with top-level await. Use import() instead.

Which makes me believe that the flag, although present in process.execArgv and detected by node in CLI, is never actually used by NW.js.

Expected/Proposed Behavior

Passing the experimental flag --experimental-require-module (which is no longer needed in node>23.x, BTW, but that flag thing might be deeper than just that? Idk.) should activate the require() of ES Modules.

Additional Info

Tests were done using require('webtorrent') (v.2.5.7, which is an async ES module) either in node (working but throws an async error, which is expected) or in NW.js' devtools (not working at all)
nw_n02OBrbrGn

  • Operating System: Windows 11 x64 24H2
  • NW.js Version: 0.93.0-sdk
@vankasteelj
Copy link
Author

vankasteelj commented Nov 23, 2024

Actually some other things that "should" work in Node don't work in NWjs. Take this example, that works fine in Node, but not in NW.js (to load an ESM in CJS, here the example is with webtorrent again) :

//note: copyright-free 'big buck bunny' cartoon
var magnet = 'magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent';

var Webtorrent = await import('webtorrent');
var Client = new Webtorrent.default(); 

Client.add(magnet, (torrent) => {
  console.log('torrent is', torrent) // <== this never happens in NW.js, but happens in Node
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant