swc-project/swc · error
failed to parse targets
Error message
failed to parse targets
What it means
In From<Config> for EnvConfig in swc_ecma_preset_env, targets_to_versions failed to convert the configured targets (and optional browserslist path) into Versions. This fires at preset_env setup when the `targets` option is malformed — an invalid browserslist query, bad config file path, or wrongly shaped target map — so the transform cannot determine which syntax/features to compile down.
Source
Thrown at crates/swc_ecma_preset_env/src/lib.rs:711
struct CoreJSConfig {
targets: Arc<Versions>,
included_modules: FxHashSet<String>,
excluded_modules: FxHashSet<String>,
/// True if the browserslist query returned an empty result (unknown browser
/// version).
unknown_version: bool,
}
pub struct EnvConfig {
config: Config,
feature_config: Arc<FeatureConfig>,
core_js_config: CoreJSConfig,
}
impl From<Config> for EnvConfig {
fn from(mut config: Config) -> Self {
let target_info = targets_to_versions(config.targets.take(), config.path.take())
.expect("failed to parse targets");
let is_any_target = target_info.versions.is_any_target();
let (include, included_modules) = FeatureOrModule::split(config.include.clone());
let (exclude, excluded_modules) = FeatureOrModule::split(config.exclude.clone());
let feature_config = FeatureConfig {
targets: Arc::clone(&target_info.versions),
include,
exclude,
is_any_target,
unknown_version: target_info.unknown_version,
force_all_transforms: config.force_all_transforms,
bugfixes: config.bugfixes,
};
let core_js_config = CoreJSConfig {
targets: Arc::clone(&target_info.versions),
included_modules,
excluded_modules,View on GitHub (pinned to 5176682b65)
Solutions
- Check the `targets` field of the preset_env config for valid browserslist query syntax
- Verify the browserslist config `path` points to an existing, valid file
- Validate the same targets against the browserslist CLI
- Use explicit version maps like { chrome: 80 } instead of free-form queries
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_ecma_preset_env/src/lib.rs:711 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/f6b89c3ba675f4c1.
Report an issue: GitHub.