From 3c07f10e04ed2dd2c5fadb8643468f30be4a0b15 Mon Sep 17 00:00:00 2001 From: kawaemon Date: Mon, 26 Aug 2024 03:20:37 +0900 Subject: [PATCH 1/2] Specify `"type": "module"` when deploying to nodejs-module --- crates/cli-support/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/cli-support/src/lib.rs b/crates/cli-support/src/lib.rs index cf37a130616..07aaf490221 100755 --- a/crates/cli-support/src/lib.rs +++ b/crates/cli-support/src/lib.rs @@ -640,12 +640,16 @@ impl Output { .with_context(|| format!("failed to write `{}`", path.display()))?; } - if !gen.npm_dependencies.is_empty() { + let is_genmode_nodemodule = matches!(gen.mode, OutputMode::Node { module: true }); + if !gen.npm_dependencies.is_empty() || is_genmode_nodemodule { #[derive(serde::Serialize)] struct PackageJson<'a> { + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + ty: Option<&'static str>, dependencies: BTreeMap<&'a str, &'a str>, } let pj = PackageJson { + ty: is_genmode_nodemodule.then_some("module"), dependencies: gen .npm_dependencies .iter() From 0228d7cac9acd8bf79012ce9ac4d7df5deeb26a8 Mon Sep 17 00:00:00 2001 From: kawaemon Date: Mon, 26 Aug 2024 03:30:08 +0900 Subject: [PATCH 2/2] Add Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee519b69adc..9cce05f80c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ * Fixed emitted `package.json` structure to correctly specify its dependencies [#4091](https://github.com/rustwasm/wasm-bindgen/pull/4091) +* Specify `"type": "module"` when deploying to nodejs-module + [#4092](https://github.com/rustwasm/wasm-bindgen/pull/4092) + -------------------------------------------------------------------------------- ## [0.2.93](https://github.com/rustwasm/wasm-bindgen/compare/0.2.92...0.2.93)