Skip to content

Commit

Permalink
syscall/js: make wasm_exec.js compatible with Webpack
Browse files Browse the repository at this point in the history
In Webpack, require("fs") will always be empty. This behavior throws an error: "fs.writeSync is not function". It happens when you did "fmt.Println".
This PR avoids such problem and use polyfill in wasm_exec.js on Webpack.

Change-Id: I55f2c75ce86b7f84d2d92e8e217b5decfbe3c8a1
GitHub-Last-Rev: aecc847
GitHub-Pull-Request: golang#35805
Reviewed-on: https://go-review.googlesource.com/c/go/+/208600
Reviewed-by: Richard Musiol <[email protected]>
  • Loading branch information
Lesmiscore authored and Richard Musiol committed Mar 24, 2020
1 parent f0e8b81 commit 9ef61d5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion misc/wasm/wasm_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
}

if (!global.fs && global.require) {
global.fs = require("fs");
const fs = require("fs");
if (Object.keys(fs) !== 0) {
global.fs = fs;
}
}

const enosys = () => {
Expand Down

0 comments on commit 9ef61d5

Please sign in to comment.