{"record":{"id":"f4c1f8f6b37e05ab","repo":"swc-project/swc","slug":"env-and-jsc-target-cannot-be-used-together","errorCode":null,"errorMessage":"`env` and `jsc.target` cannot be used together","messagePattern":"`env` and `jsc\\.target` cannot be used together","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc/src/config/mod.rs","lineNumber":332,"sourceCode":"        let loose = loose.into_bool();\n        let preserve_all_comments = preserve_all_comments.into_bool();\n        let preserve_symlinks = preserve_symlinks.into_bool();\n        let keep_class_names = keep_class_names.into_bool();\n        let external_helpers = external_helpers.into_bool();\n\n        let mut assumptions = assumptions.unwrap_or_else(|| {\n            if loose {\n                Assumptions::all()\n            } else {\n                Assumptions::default()\n            }\n        });\n\n        let unresolved_mark = self.unresolved_mark.unwrap_or_default();\n        let top_level_mark = self.top_level_mark.unwrap_or_default();\n\n        if target.is_some() && cfg.env.is_some() {\n            bail!(\"`env` and `jsc.target` cannot be used together\");\n        }\n\n        let es_version = target.unwrap_or_default();\n\n        let syntax = syntax.unwrap_or_default();\n\n        let (mut program, flow_strip_script_like_module) = parse(syntax, es_version, is_module)?;\n\n        let mut transform = transform.into_inner().unwrap_or_default();\n\n        #[cfg(feature = \"react-compiler\")]\n        if let Some(options) = react_compiler_options(transform.react_compiler.clone(), base) {\n            let fm = if program.span().is_dummy() {\n                cm.get_source_file(base)\n            } else {\n                cm.try_lookup_byte_offset(program.span().lo)\n                    .ok()\n                    .map(|source| source.sf)","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc/src/config/mod.rs#L314-L350","documentation":"SWC rejects options that set both `env` (the babel-preset-env-style transform, configured with `env` / `env.targets`) and `jsc.target` (the single ES version for the core compiler). Both fields drive how far output is downgraded, so combining them makes the target ambiguous. The check runs during option building in crates/swc/src/config/mod.rs before any parsing happens, so it is purely a configuration error and the input file is never read.","triggerScenarios":"Calling Compiler::process_js_file / process_js_with_custom_pass, or @swc/core transform/transformFile, with options where both `env: { targets: ... }` and `jsc: { target: 'es5' }` are present; also merging a .swcrc that contains an `env` block with a CLI `--target` flag or framework-injected jsc.target.","commonSituations":"Translating a Babel config (preset-env) to swc's `env` and then also setting jsc.target 'for safety'; older swc versions tolerating both and failing after an upgrade; frameworks (Next.js, jest transformers, Vite plugins) injecting `env` while user config sets jsc.target.","solutions":["Delete `jsc.target` from the .swcrc / options and express all target requirements under `env.targets`","Or remove the `env` block entirely and keep only `jsc.target` when you don't need preset-env-style target matrices","If the target came from a CLI flag like `--target es2017`, remove the `env` key from the .swcrc it gets merged with","Print the fully merged options reaching swc to find which layer (framework, CLI, config file) injects the conflicting field"],"exampleFix":"// before (.swcrc)\n{\n  \"env\": { \"targets\": \"> 0.25%\" },\n  \"jsc\": { \"target\": \"es5\", \"parser\": { \"syntax\": \"typescript\" } }\n}\n// after (.swcrc)\n{\n  \"env\": { \"targets\": \"> 0.25%\" },\n  \"jsc\": { \"parser\": { \"syntax\": \"typescript\" } }\n}","handlingStrategy":"validation","validationCode":"// TypeScript / @swc/core - run before transform\nfunction assertNoTargetConflict(opts: { env?: unknown; jsc?: { target?: string } }) {\n  if (opts.env != null && opts.jsc?.target != null) {\n    throw new Error(\n      'swc: `env` and `jsc.target` cannot be used together; keep env.targets and drop jsc.target'\n    );\n  }\n}\nassertNoTargetConflict(options); // your swc options object","typeGuard":"type SwcOptions = { env?: object; jsc?: { target?: string } };\nconst hasTargetConflict = (o: SwcOptions): o is SwcOptions & { env: object; jsc: { target: string } } =>\n  o.env != null && o.jsc?.target != null;","tryCatchPattern":null,"preventionTips":["Pick one target mechanism per project: env.targets for preset-env behavior, jsc.target otherwise","When layering config (framework + .swcrc + CLI flags), log the final merged options in CI","Add a unit test asserting your generated swc config never contains both keys"],"tags":["swc","config","jsc-target","preset-env","conflicting-options"],"backgroundTag":"conflicting-config-options","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}