Skip to content

Faulty assertion in node on .mjs files #17465

Open
@kripken

Description

@kripken

It turns out that node will disable the global require function on foo.mjs - that is just not defined there, unlike for foo.js. I guess mjs files are modules and require is not supposed to be used there. This ends up a problem for us since we have an assertion on it:

emscripten/src/shell.js

Lines 196 to 198 in a3d8979

#if ASSERTIONS
if (!(typeof process == 'object' && typeof require == 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
#endif

Removing that assertion is necessary to run an .mjs file in node with -sASSERTIONS.

We should probably just remove it?

This happens on binaryen CI which will manually builds an .mjs file by concatenating the emcc output with some extra code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions