swc-project/swc · warning

jsc.experimental.emitIsolatedDts is enabled but the syntax i

Error message

jsc.experimental.emitIsolatedDts is enabled but the syntax is not TypeScript

What it means

Warned by swc's process_js when jsc.experimental.emitIsolatedDts is enabled but the parser syntax is not TypeScript. Isolated .d.ts emission works only on TS syntax; with ecmascript syntax the option is a no-op and SWC tells you so.

Source

Thrown at crates/swc/src/lib.rs:1250

    #[cfg_attr(
        debug_assertions,
        tracing::instrument(name = "swc::Compiler::apply_transforms", skip_all)
    )]
    fn apply_transforms(
        &self,
        handler: &Handler,
        #[allow(unused)] comments: SingleThreadedComments,
        #[allow(unused)] fm: Arc<SourceFile>,
        orig: Option<sourcemap::SourceMap>,
        config: BuiltInput<impl Pass>,
    ) -> Result<TransformOutput, Error> {
        self.run(|| {
            let program = config.program;
            let is_typescript_syntax = matches!(config.syntax, Syntax::Typescript(..));

            if config.emit_isolated_dts && !is_typescript_syntax {
                handler.warn(
                    "jsc.experimental.emitIsolatedDts is enabled but the syntax is not TypeScript",
                );
            }

            let source_map_names = if config.source_maps.enabled() {
                let mut v = swc_compiler_base::IdentCollector {
                    names: Default::default(),
                };

                program.visit_with(&mut v);

                v.names
            } else {
                Default::default()
            };
            #[cfg(feature = "isolated-dts")]
            let dts_code = if is_typescript_syntax && config.emit_isolated_dts {
                use std::cell::RefCell;

View on GitHub (pinned to 5176682b65)

Solutions

  1. Set jsc.parser.syntax to "typescript" (or "typescript" with tsx) for files where you want isolated dts output.
  2. Disable jsc.experimental.emitIsolatedDts for non-TS files or split the config per file type.
  3. Scope the option via overrides/multiple configs so .js inputs do not inherit it.

Example fix

// before
const options = {
  jsc: {
    parser: { syntax: "ecmascript" },
    experimental: { emitIsolatedDts: true },
  },
};

// after
const options = {
  jsc: {
    parser: { syntax: "typescript", tsx: true },
    experimental: { emitIsolatedDts: true },
  },
};
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling transform: dts emission requires TS syntax.
export function assertDtsConfigConsistent(options: {
  jsc?: { parser?: { syntax?: string }; experimental?: { emitIsolatedDts?: boolean } };
}): void {
  const syntax = options.jsc?.parser?.syntax;
  const dts = options.jsc?.experimental?.emitIsolatedDts;
  if (dts && syntax !== 'typescript' && syntax !== 'tsx') {
    throw new Error(
      `emitIsolatedDts requires jsc.parser.syntax 'typescript'; got '${syntax}'`
    );
  }
}

Type guard

function isTypescriptSyntax(syntax?: string): boolean {
  return syntax === 'typescript' || syntax === 'tsx';
}

Prevention

When it happens

Trigger: Config sets jsc.experimental.emitIsolatedDts: true (or --experimental-emit-isolated-dts) together with jsc.parser.syntax: "ecmascript"; also when a shared config applies dts emission to .js/.mjs files.

Common situations: Reusing a TypeScript-oriented .swcrc for plain JavaScript files; monorepos with one config across .ts and .js; migrating configs where the parser block was changed but the experimental option was left behind.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/0359072e70854316. Report an issue: GitHub.