swc-project/swc · error

no config matched for file ({name})

Error message

no config matched for file ({name})

What it means

Thrown by Compiler::try_build_config: the effective config (from a config file or the default Rc) resolved via `into_config(filename)` to None, meaning its test/exclude filters do not claim the given file. For a single-entry config one failed match immediately yields None; for multi-entry configs no entry matched. The surrounding context adds 'failed to read .swcrc file for input file at `...`'.

Source

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

                    return Ok(config);
                }

                let config_file = config_file.unwrap_or_default();
                let config = config_file.into_config(Some(filename_path))?;

                return Ok(config);
            }

            let config = match config_file {
                Some(config_file) => config_file.into_config(None)?,
                None => Rc::default().into_config(None)?,
            };

            match config {
                Some(config) => Ok(Some(config)),
                None => {
                    bail!("no config matched for file ({name})")
                }
            }
        })
        .with_context(|| format!("failed to read .swcrc file for input file at `{name}`"))
    }

    /// This method returns [None] if a file should be skipped.
    ///
    /// This method handles merging of config.
    ///
    /// This method does **not** parse module.
    #[cfg_attr(debug_assertions, tracing::instrument(skip_all))]
    pub fn parse_js_as_input<'a, P>(
        &'a self,
        fm: Lrc<SourceFile>,
        program: Option<Program>,
        handler: &'a Handler,
        opts: &Options,

View on GitHub (pinned to 5176682b65)

Solutions

  1. Adjust `test`/`exclude` in the config entry so the file matches
  2. Add an additional entry covering the file type
  3. If the file is meant to be skipped, filter it out before invoking swc instead of relying on config matching

Example fix

// before
{ "test": "\\.tsx?$", "exclude": "node_modules" }
// after
{ "test": "\\.(m|c)?tsx?$", "exclude": "(^|/)node_modules/" }
Defensive patterns

Strategy: validation

Validate before calling

// JavaScript - pre-check file coverage against the active config
function isFileCovered(config, filePath) {
  const test = config.test ? new RegExp(config.test) : null;
  const excl = config.exclude ? new RegExp(config.exclude) : null;
  return (!test || test.test(filePath)) && !(excl && excl.test(filePath));
}
const covered = (Array.isArray(cfg) ? cfg : [cfg]).some((c) => isFileCovered(c, file));
if (!covered) throw new Error(`config does not cover ${file}`);

Prevention

When it happens

Trigger: Programmatic Compiler use (swc CLI paths, custom integrations) where a config exists but `test` doesn't cover the file's extension or `exclude` matches its path.

Common situations: Extension not covered by test patterns; exclude patterns matching more than intended; path-form mismatches (Windows separators) breaking regexes; default-config fallback when no config file was supposed to be used.

Related errors


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