-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emscripten fails on Node.js with PThreads and ES6 exports #18626
Comments
This is also fixable for me by renaming the *.worker.js file to *.worker.cjs and also changing the filename where it's used in the primary *.mjs file. (Edit: Actually, this breaks compatibility with the browser because the .cjs file has an application/node MIME type, which browsers don't expect...) Either the .worker.js file should become an ES6 module itself, or at least it should get a filename that reflects that it's a CommonJS module in an ES6 environment |
Is there any progress on this issue please? I was able to work around this using @toBeOfUse as a test but it does break the browser build. |
My solution is to include a dummy {
"type": "commonjs"
} |
I think this has been fixed with PR #21041, available in the (upcoming) v3.1.52 release. |
Lets close this out for now and we can re-open if it doesn't actually fix the issue. |
@sbc100 Hi, I'm facing this issue in v3.1.52, when using guyutongxue@GuyuDesktop:~$ cat temp.c
int main() {}
guyutongxue@GuyuDesktop:~$ emcc temp.c -o temp.html -O3 -pthread -s EXPORT_ES6 -s MODULARIZE
file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:3567
var err = new SyntaxError(message);
^
SyntaxError: Cannot use keyword 'await' outside an async function (24:28)
const { createRequire } = await import('module');
^
at Parser.pp$4.raise (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:3567:13)
at Parser.pp$5.checkUnreserved (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:3465:14)
at Parser.pp$5.parseIdent (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:3479:10)
at Parser.pp$5.parseExprAtom (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:2849:19)
at Parser.pp$5.parseExprSubscripts (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:2709:19)
at Parser.pp$5.parseMaybeUnary (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:2675:17)
at Parser.pp$5.parseExprOps (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:2602:19)
at Parser.pp$5.parseMaybeConditional (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:2585:19)
at Parser.pp$5.parseMaybeAssign (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:2552:19)
at Parser.pp$8.parseVar (file:///home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/node_modules/acorn/dist/acorn.mjs:1315:24) {
pos: 836,
loc: Position { line: 24, column: 28 },
raisedAt: 848
}
emcc: error: '/home/guyutongxue/clangd-wasm-build/emsdk/node/16.20.0_64bit/bin/node /home/guyutongxue/clangd-wasm-build/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs /home/guyutongxue/temp.worker.mjs minifyWhitespace --exportES6' failed (returned 1) |
I believe that should be fixed in #21117. That change will be in the next release (3.1.53) or you can use |
Nice, thank you 😄 |
tl;dr Compiling with ES6, PThreads and Node options produces a not-quite-right
*.worker.js
file.I have some C++ code that uses PThreads (greatly simplified below, let's call it
dummy.cpp
):I compile this for Node.js with ES6 export, using Emscripten version 3.1.31 (e883361):
I create the following script (
test.js
) - I also add apackage.json
with"type": "module"
to treat it as ES6:And then run it (using Node v16.19.0), which throws the following error:
And indeed, if I look at
dummy.worker.js
, there are a fewrequire
statements in there. There is also a mysterious__filename
variable that is not defined anywhere in this file. Seems like some extra statements are required at the start:Once I add them, the script will happily run:
I couldn't find any information here about not combining PThreads + ES6 + Node, so I figured that this behavior was a bug. Bit surprised that no one's reported this before, actually; I suppose ES6 hasn't really caught on with Node users yet.
The text was updated successfully, but these errors were encountered: