nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.31k stars 3.88k forks source link

"node-main" when specified as a module (.mjs or "type"="module" in package.json) silently fails if there bug in it. #7766

Open CxRes opened 3 years ago

CxRes commented 3 years ago

I apologise in advance for filing this issue in lieu of #7761. I fear that the issue will otherwise be ignored due to this new discovery being lost in subsequent comments.

NWJS Version : 0.55.0 Operating System : Windows 10 x64

Expected behavior

Errors should shows up in the devtools > console when node-main file is specified to be a module (either when specified with .mjs extension or "type":"module" in package.json) and there is a bug in the file, just as they do when node-main is not a es module.

Actual behavior

No error shows up in the devtools > console when node-main file is specified to be a module and there is a bug in the file.

How to reproduce

package.json

{
  "name": "test-nwjs",
  "main": "main.js",
  "node-main": "node-main.js",
}

node-main.js

const x = 1; x = 2;

main.js

nw.Window.open('./index.html', {
  show: true,
  position: 'center',
});

index.html

<h1>Hello World!</h1>

Error is displayed in devtools > console as expected. So far so good!

Now lets add to package.json "type"="module"

{
  "name": "test-nwjs",
  "main": "main.js",
  "node-main": "node-main.js",
  "type":"module"
}

You will now find that devtools > console is empty.

CxRes commented 3 years ago

Incidentally, in the non-module case for node-main, if you use the --mixed-context flag, the error is reported twice, both in devtools for the background page as well as the loaded web page (The same thing does not happen, say, for the main file).