Skip to content

Fix: Quote non-identifier export names in ESM library output#12968

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-json-import-key-error
Draft

Fix: Quote non-identifier export names in ESM library output#12968
Copilot wants to merge 3 commits intomainfrom
copilot/fix-json-import-key-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

JSON keys containing special characters (!, ., -, etc.) were generating invalid export statements in ESM library output, causing syntax errors during minification or consumption.

Changes

  • Modified render_as_named_exports_impl in modern_module_library_plugin.rs to use the existing export_name utility function, which properly quotes identifiers that aren't valid JavaScript identifiers
  • Added test case covering JSON exports with special character keys

Example

Before:

export { __webpack_exports___top as !top }  // Syntax error

After:

export { __webpack_exports___top as "!top" }  // Valid

Affects modern-module and module library types when exporting JSON with non-standard property names.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Importing a JSON file containing ! in a key results in a malformed js export statement</issue_title>
<issue_description>### System Info

System:
OS: Windows 11 10.0.26200
CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13800H
Memory: 15.39 GB / 63.67 GB
Binaries:
Node: 22.19.0 - C:\Program Files\nodejs\node.EXE
Yarn: 4.12.0 - C:\Program Files\nodejs\yarn.CMD
npm: 10.9.3 - C:\Program Files\nodejs\npm.CMD
bun: 1.3.2 - ~.bun\bin\bun.EXE
Browsers:
Edge: Chromium (140.0.3485.54)
Internet Explorer: 11.0.26100.7309

Details

Trying to import a JSON file containing a key that starts with !, like "!top", results in a JavaScript parse error: Unexpected token !. Expected identifier or string error when minifying via SWC or using the bundled code in other projects.

rslib (non bundled) generates the export key as export { __webpack_exports___top as !top, ... } instead of export { __webpack_exports___top as "!top", ... }.

I would expect rspack to use "!top" instead of !top.

Reproduce link

Link

Reproduce Steps

  1. Import the relevant JSON file via import fileName from './file-name.json';
  2. Make sure that minification is enabled and run rslib build with format configured to esm

Example JSON:
{ "!top": [] }</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 6, 2026 08:23
Co-authored-by: hardfist <8898718+hardfist@users.noreply.github.com>
Co-authored-by: hardfist <8898718+hardfist@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JSON import error with keys starting with ! Fix: Quote non-identifier export names in ESM library output Feb 6, 2026
Copilot AI requested a review from hardfist February 6, 2026 08:45
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

📦 Binary Size-limit

Comparing 0f6ba46 to fix: Replace AtomicRefCell with Mutex in RSC Coordinator (#12972) by Cong-Cong Pan

🎉 Size decreased by 16.25KB from 48.57MB to 48.56MB (⬇️0.03%)

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing copilot/fix-json-import-key-error (0f6ba46) with main (c4c9877)1

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark2

Footnotes

  1. No successful run was found on main (d177542) during the generation of this report, so c4c9877 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Importing a JSON file containing ! in a key results in a malformed js export statement

2 participants