Skip to content

esm: unflag --experimental-wasm-modules #57038

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ entry point, the `node` command will accept as input only files with `.js`,
`.mjs`, or `.cjs` extensions. With the following flags, additional file
extensions are enabled:

* [`--experimental-wasm-modules`][] for files with `.wasm` extension.
* [`--experimental-addon-modules`][] for files with `.node` extension.

## Options
Expand Down Expand Up @@ -1124,14 +1123,6 @@ changes:

Enable experimental WebAssembly System Interface (WASI) support.

### `--experimental-wasm-modules`

<!-- YAML
added: v12.3.0
-->

Enable experimental WebAssembly module support.

### `--experimental-webstorage`

<!-- YAML
Expand Down Expand Up @@ -3198,7 +3189,6 @@ one is included in the list below.
* `--experimental-transform-types`
* `--experimental-vm-modules`
* `--experimental-wasi-unstable-preview1`
* `--experimental-wasm-modules`
* `--experimental-webstorage`
* `--force-context-aware`
* `--force-fips`
Expand Down Expand Up @@ -3758,7 +3748,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`--env-file`]: #--env-fileconfig
[`--experimental-addon-modules`]: #--experimental-addon-modules
[`--experimental-sea-config`]: single-executable-applications.md#generating-single-executable-preparation-blobs
[`--experimental-wasm-modules`]: #--experimental-wasm-modules
[`--heap-prof-dir`]: #--heap-prof-dir
[`--import`]: #--importmodule
[`--no-experimental-strip-types`]: #--no-experimental-strip-types
Expand Down
12 changes: 9 additions & 3 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,16 @@ imported from the same path.

## Wasm modules

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57038
description: Wasm modules no longer require the `--experimental-wasm-modules` flag.
-->

> Stability: 1 - Experimental
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> Stability: 1 - Experimental
> Stability: 1.2 - Release candidate


Importing WebAssembly modules is supported under the
`--experimental-wasm-modules` flag, allowing any `.wasm` files to be
Importing WebAssembly modules is supported, allowing any `.wasm` files to be
imported as normal modules while also supporting their module imports.

This integration is in line with the
Expand All @@ -686,7 +692,7 @@ console.log(M);
executed under:

```bash
node --experimental-wasm-modules index.mjs
node index.mjs
```

would provide the exports interface for the instantiation of `module.wasm`.
Expand Down
3 changes: 0 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ Enable experimental ES module support in VM module.
Enable experimental WebAssembly System Interface support. This
flag is no longer required as WASI is enabled by default.
.
.It Fl -experimental-wasm-modules
Enable experimental WebAssembly module support.
.
.It Fl -experimental-quic
Enable the experimental QUIC support.
.
Expand Down
9 changes: 2 additions & 7 deletions lib/internal/modules/esm/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { getValidatedPath } = require('internal/fs/utils');
const fsBindings = internalBinding('fs');
const { fs: fsConstants } = internalBinding('constants');

const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
const experimentalAddonModules = getOptionValue('--experimental-addon-modules');

const extensionFormatMap = {
Expand All @@ -18,12 +17,9 @@ const extensionFormatMap = {
'.js': 'module',
'.json': 'json',
'.mjs': 'module',
'.wasm': 'wasm',
};

if (experimentalWasmModules) {
extensionFormatMap['.wasm'] = 'wasm';
}

if (experimentalAddonModules) {
extensionFormatMap['.node'] = 'addon';
}
Expand All @@ -46,7 +42,7 @@ function mimeToFormat(mime) {
) !== null
) { return 'module'; }
if (mime === 'application/json') { return 'json'; }
if (experimentalWasmModules && mime === 'application/wasm') { return 'wasm'; }
if (mime === 'application/wasm') { return 'wasm'; }
return null;
}

Expand All @@ -57,7 +53,6 @@ function mimeToFormat(mime) {
* @param {URL} url
*/
function getFormatOfExtensionlessFile(url) {
if (!experimentalWasmModules) { return 'module'; }
const path = getValidatedPath(url);
switch (fsBindings.getFormatOfExtensionlessFile(path)) {
case fsConstants.EXTENSIONLESS_FORMAT_WASM:
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,6 @@ translators.set('json', function jsonStrategy(url, source) {

// Strategy for loading a wasm module
translators.set('wasm', async function(url, source) {
emitExperimentalWarning('Importing WebAssembly modules');

assertBufferSource(source, false, 'load');

debug(`Translating WASMModule ${url}`);
Expand Down
5 changes: 1 addition & 4 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
kAllowedInEnvvar);
AddAlias("--loader", "--experimental-loader");
AddOption("--experimental-modules", "", NoOp{}, kAllowedInEnvvar);
AddOption("--experimental-wasm-modules",
"experimental ES Module support for webassembly modules",
&EnvironmentOptions::experimental_wasm_modules,
kAllowedInEnvvar);
AddOption("--experimental-wasm-modules", "", NoOp{}, kAllowedInEnvvar);
Copy link
Member

@legendecas legendecas Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "unflag an experimental feature" should start with switching the default value to be true, and allowing turning the feature off with --no-experiemental-wasm-modules, instead of making it a no-op directly.

BTW, if we are going to make this a no-op, EnvironmentOptions::experimental_wasm_modules should be removed as it is not used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, if having WASM module enabled breaks something, it's useful to be able to disable it. We can make the falg a no-op in another major

AddOption("--experimental-import-meta-resolve",
"experimental ES Module import.meta.resolve() parentURL support",
&EnvironmentOptions::experimental_import_meta_resolve,
Expand Down
22 changes: 1 addition & 21 deletions test/es-module/test-esm-wasm.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { strictEqual, match } from 'node:assert';
import { strictEqual } from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should load exports', async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-wasm-modules',
'--input-type=module',
'--eval',
[
Expand All @@ -31,8 +29,6 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>

it('should not allow code injection through export names', async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-wasm-modules',
'--input-type=module',
'--eval',
`import * as wasmExports from ${JSON.stringify(fixtures.fileURL('es-modules/export-name-code-injection.wasm'))};`,
Expand All @@ -45,8 +41,6 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>

it('should allow non-identifier export names', async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-wasm-modules',
'--input-type=module',
'--eval',
[
Expand All @@ -63,8 +57,6 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>

it('should properly escape import names as well', async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-wasm-modules',
'--input-type=module',
'--eval',
[
Expand All @@ -78,16 +70,4 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>
strictEqual(stdout, '');
strictEqual(code, 0);
});

it('should emit experimental warning', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--experimental-wasm-modules',
fixtures.path('es-modules/wasm-modules.mjs'),
]);

strictEqual(code, 0);
strictEqual(signal, null);
match(stderr, /ExperimentalWarning/);
match(stderr, /WebAssembly/);
});
});
3 changes: 1 addition & 2 deletions test/module-hooks/test-module-hooks-import-wasm.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Flags: --no-experimental-wasm-modules
// This tests that module.registerHooks() can be used to support unknown formats, like
// import(wasm) (without --experimental-wasm-modules).
// import(wasm)
import '../common/index.mjs';

import assert from 'node:assert';
Expand Down
3 changes: 1 addition & 2 deletions test/module-hooks/test-module-hooks-require-wasm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Flags: --no-experimental-wasm-modules
'use strict';

// This tests that module.registerHooks() can be used to support unknown formats, like
// require(wasm) and import(wasm) (without --experimental-wasm-modules).
// require(wasm) and import(wasm)
const common = require('../common');

const assert = require('assert');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ assert(undocumented.delete('--debug-arraybuffer-allocations'));
assert(undocumented.delete('--no-debug-arraybuffer-allocations'));
assert(undocumented.delete('--es-module-specifier-resolution'));
assert(undocumented.delete('--experimental-fetch'));
assert(undocumented.delete('--experimental-wasm-modules'));
assert(undocumented.delete('--experimental-global-customevent'));
assert(undocumented.delete('--experimental-global-webcrypto'));
assert(undocumented.delete('--experimental-report'));
Expand Down
Loading