Current status of NW.js ES6 module support

340 views
Skip to first unread message

Tom Coleman

unread,
Oct 11, 2021, 8:30:48 AM10/11/21
to nw.js
Hi,

I am quite new to js dev and am trying to work out what is possible in NW.js with respect to ES6 modules. As the status/support of ES6 modules - especially in regard to node.js dev - seems to be in a state of flux recently (last year or so)  a lot of the information around the place seems to be out of date.

I am wondering, is it possible to use ES6 modules for my nw.js app. Currently I have a html entry point and importing my mjs source with a script tag with type="module". Seems to parse ok, but a simple:

import * as worker from 'worker_threads';

Results in the error:
Uncaught TypeError: Failed to resolve module specifier "worker_threads". Relative references must start with either "/", "./", or "../".

It seems like I can import a local file with ES6 import syntax ok.

I have also been playing around with Electron which has certain odd restrictions which modules can be imported with import/require so I am wondering if I am doing something wrong or there are certain fundamental restrictions with importing. I would have thought being based on recent node versions that import of built-in node modules with ES6 syntax would be possible.

russell....@gmail.com

unread,
Oct 25, 2021, 6:09:42 PM10/25/21
to nw.js
I've just been using webpack and babel. Probably not the answer you are looking for. There are a few people asking similar in github issues, such as:
Reply all
Reply to author
Forward
0 new messages