Skip to content

Commit e28df40

Browse files
committed
Catch and ignore the error if fs module can't be required.
There are environments like AMD, which expose `require()` function, but do not provide `fs` module. In such cases we should fall back to our stub (see #693 (comment)).
1 parent bc8384e commit e28df40

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/prelude/prelude.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ if (typeof module !== "undefined") {
2727
}
2828
2929
if (!$global.fs && $global.require) {
30-
var fs = $global.require('fs');
31-
if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
32-
$global.fs = fs;
33-
}
30+
try {
31+
var fs = $global.require('fs');
32+
if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
33+
$global.fs = fs;
34+
}
35+
} catch(e) { /* Ignore if the module couldn't be loaded. */ }
3436
}
3537
3638
if (!$global.fs) {

0 commit comments

Comments
 (0)