swc-project/swc · error

failed to find input source map file

Error message

failed to find input source map file {:?} in {:?} file as either {:?} or with appended .map

What it means

The input file's `sourceMappingURL` comment names an external map file; swc resolved it relative to the input file's directory and also tried the legacy fallback `<inputfile>.map`; neither exists on disk, so processing aborts. The message includes the sourceMappingURL value, the input file path, and the candidate map path that was checked.

Solutions

  1. Restore the .map file at the exact path the comment references, relative to the input file
  2. Or remove the `//# sourceMappingURL=` comment from the input file
  3. Or tell swc not to read input maps (e.g. `inputSourceMap: false` in @swc/core options) when they are intentionally absent

Example fix

// before
//# sourceMappingURL=./maps/index.js.map   /* file missing */
// after: either ship ./maps/index.js.map, or drop the comment / disable reading it
const out = await transformFile('index.js', { inputSourceMap: false });
Defensive patterns

Strategy: validation

Validate before calling

// JavaScript - verify referenced external map exists before compiling
import fs from 'node:fs';
import path from 'node:path';
function assertInputSourceMapExists(source, filePath) {
  const m = source.match(/\/\/[#@]\s*sourceMappingURL=(\S+)/);
  if (!m || m[1].startsWith('data:')) return;
  const candidates = [
    path.resolve(path.dirname(filePath), m[1]),
    `${filePath}.map`,
  ];
  if (!candidates.some((p) => fs.existsSync(p))) {
    throw new Error(`missing source map for ${filePath}: ${m[1]}`);
  }
}

Prevention

When it happens

Trigger: Compiling a JS file containing `//# sourceMappingURL=foo.js.map` where foo.js.map was deleted or never deployed next to the file; map in a different directory than the referencing file; case mismatches on case-sensitive filesystems.

Common situations: Committing or deploying compiled .js without the .map; CI copying only .js artifacts; moving/renaming files after build; consuming transpiled sources from CDNs where maps aren't shipped.

Related errors


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

Appendix: source

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

                            };

                            let map_path = match data_url {
                                Some(data_url) => {
                                    let mut map_path = dir.join(data_url);
                                    if !map_path.exists() {
                                        // Old behavior. This check would prevent
                                        // regressions.
                                        // Perhaps it shouldn't be supported. Sometimes
                                        // developers don't want to expose their source
                                        // code.
                                        // Map files are for internal troubleshooting
                                        // convenience.
                                        let fallback_map_path =
                                            PathBuf::from(format!("{}.map", filename.display()));
                                        if fallback_map_path.exists() {
                                            map_path = fallback_map_path;
                                        } else {
                                            bail!(
                                                "failed to find input source map file {:?} in \
                                                 {:?} file as either {:?} or with appended .map",
                                                data_url,
                                                filename.display(),
                                                map_path.display(),
                                            )
                                        }
                                    }

                                    Some(map_path)
                                }
                                None => {
                                    // Old behavior.
                                    let map_path =
                                        PathBuf::from(format!("{}.map", filename.display()));
                                    if map_path.exists() {
                                        Some(map_path)
                                    } else {

View on GitHub (pinned to 5176682b65)