In a Node-Webkit application running on the latest stable release (v0.18.8), I have these three lines:
console.log("Check 1");
var spawn = require('child_process').spawn;
console.log("Check 2");
When I have Internet, I get the expected output:
Check 1
Check 2
When I disconnect from the Internet, or there is no network available, I get:
Check 1
net.js:10 Uncaught Error: EFILE
at net.js:10:23
at NativeModule.compile (bootstrap_node.js:531:7)
at NativeModule.require (bootstrap_node.js:472:18)
at internal/child_process.js:6:13
at NativeModule.compile (bootstrap_node.js:531:7)
at NativeModule.require (bootstrap_node.js:472:18)
at child_process.js:12:23
at NativeModule.compile (bootstrap_node.js:531:7)
at Function.NativeModule.require (bootstrap_node.js:472:18)
at Function.Module._load (module.js:446:25)
The console.log("Check 2")
is never run, and the rest of the script is ignored.
I shouldn't need an Internet connection to require something, so I'm confused as to what's going wrong here. This error also happens with some other require()
statements, but not all. For example, require('nw.gui')
works fine.
How can I use require()
without an Internet connection?
I'm running Windows 10, 64-bit.
Here's an example demonstrating the issue:
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Title</title>
</head>
<body>
<p>Body</p>
</body>
<script type="text/javascript">
console.log("Check 1");
var spawn = require('child_process').spawn;
console.log("Check 2");
</script>
</html>
package.json
{
"name": "Demo",
"version": "1.0.0",
"main": "index.html"
}
Place these two files in a folder and run with Node-Webkit with Internet and without. Press F12 to open the developer tools. There should be no error when run with Internet, and an error when run without.