-
-
Notifications
You must be signed in to change notification settings - Fork 727
Description
System Info
System:
OS: macOS 14.4
CPU: (12) arm64 Apple M3 Pro
Memory: 100.22 MB / 18.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.19.5
pnpm: 10.15.1
Browsers:
Chrome: 127.0.6533.100
Firefox: 140.0.2
Safari: 17.4
npmPackages:
@rspack/cli: 1.3.1 => 1.3.1
@rspack/core: 1.3.1 => 1.3.1
@swc/plugin-emotion: 9.0.3
Details
When using @swc/plugin-emotion in some rspack-based projects (including both Modern.js and Rsbuild projects), I found that the plugin’s configuration options—specifically the default values autoLabel: 'dev-only' and sourceMap: true—do not take effect as expected.
After reviewing the documentation and source code of @swc/plugin-emotion, I discovered that the plugin determines the current environment (development or production) by calling TransformPluginProgramMetadata::get_context(&TransformPluginMetadataContextKind::Env) to retrieve the environment name (env_name) from swc. This environment information is used to control different build behaviors.
To investigate further, I implemented a simple SWC plugin as a demo to print out the environment information from the metadata. I found that the environment field is an empty string. As a result, any SWC plugins that rely on this field are unable to correctly identify the current build environment, leading to incorrect or unexpected behavior.
Reproduce link
https://github.com/Zeahan/rspack-repro-swc-env-name-error/tree/main
Reproduce Steps
- Run
pnpm install - Check if the demo plugin is correctly built in the
packages/plugin-demo/targetdirectory - Run pnpm build in the project root directory and observe the env name information printed by the demo plugin in the console