swc-project/swc · error
cannot process file because it's ignored by .swcrc
Error message
cannot process file because it's ignored by .swcrc
What it means
In Compiler::process_js_inner, config resolution returned None - which by contract means 'file should be ignored' - but processing continued to the point where a config is required, so swc bails with 'cannot process file because it's ignored by .swcrc'. A None result comes from the file matching an `exclude` pattern or matching no `test` pattern in the loaded config.
Source
Thrown at crates/swc/src/lib.rs:968
P1: Pass,
P2: Pass,
{
self.run(|| -> Result<_, Error> {
let config = self.run(|| {
self.parse_js_as_input(
fm.clone(),
program,
handler,
opts,
&fm.name,
Some(&comments),
|program| custom_before_pass(program),
)
})?;
let config = match config {
Some(v) => v,
None => {
bail!("cannot process file because it's ignored by .swcrc")
}
};
let after_pass = custom_after_pass(&config.program);
let config = config.with_pass(|pass| (pass, after_pass));
let orig = if config.source_maps.enabled() {
self.get_orig_src_map(
&fm,
&config.input_source_map,
config
.comments
.get_trailing(config.program.span_hi())
.as_deref()
.unwrap_or_default(),
false,
)?View on GitHub (pinned to 5176682b65)
Solutions
- Narrow the `exclude` regex (anchor it, make it path-aware) so intended files are not excluded
- Extend `test` to cover the file's extension
- Pre-filter input files (your own ignore logic) so ignored files never reach the compiler
Example fix
// before (.swcrc)
{ "exclude": "node_modules" }
// after (.swcrc)
{ "exclude": "(^|/)node_modules/" } Defensive patterns
Strategy: validation
Validate before calling
// JavaScript - apply your own exclude/test gate before compiling
const excluded = new RegExp(cfg.exclude ?? '$^'); // '$^' never matches
const tested = cfg.test ? new RegExp(cfg.test).test(file) : true;
if (!tested || excluded.test(file)) {
console.warn(`skipping ${file} (not covered by .swcrc)`);
} else {
await transformFile(file, options);
} Prevention
- Anchor exclude patterns and make them path-aware: "(^|/)node_modules/"
- Filter inputs before invoking swc rather than relying on it to ignore
- Audit exclude patterns against your real directory names
When it happens
Trigger: Feeding a file to the swc compiler (CLI or API) whose path hits an .swcrc `exclude` regex like "node_modules" or whose extension matches no `test`, without filtering it out beforehand.
Common situations: "exclude": ["node_modules"] also matching src/lib/node_modules-style paths; test patterns not covering .mjs/.cjs/.jsx; build scripts globbing directories broader than the config's intent.
Related errors
- .swcrc exists but not matched
- no config matched for file ({name})
- {} is not a valid expression
- Could not find .swcrc file while using rootMode "upward". Se
- The requested module '{specifier}' does not provide an expor
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/f7822d69779ad2d0.
Report an issue: GitHub.