swc-project/swc · error

path does not exist: `{}`

Error message

path does not exist: `{}`

What it means

collect_flow_files starts with an existence check on the supplied path and bails immediately if it does not exist on disk. It is a fail-fast guard before any directory walking happens, so no partial work occurs. The path is displayed verbatim in the message.

Source

Thrown at crates/dbg-swc/src/es/flow/strip.rs:276

    {
        let wr = JsWriter::new(cm.clone(), "\n", &mut buf, None);
        let mut emitter = Emitter {
            cfg: CodegenConfig::default(),
            comments: None,
            cm,
            wr,
        };
        emitter
            .emit_program(program)
            .context("failed to emit transformed program")?;
    }

    String::from_utf8(buf).context("swc emitted non-utf8 output")
}

fn collect_flow_files(path: &Path) -> Result<Vec<PathBuf>> {
    if !path.exists() {
        bail!("path does not exist: `{}`", path.display());
    }

    let mut files = Vec::new();
    let mut stack = vec![path.to_path_buf()];

    while let Some(current) = stack.pop() {
        if current.is_dir() {
            let entries = current
                .read_dir()
                .with_context(|| format!("failed to read directory `{}`", current.display()))?;

            for entry in entries {
                let entry = entry.with_context(|| {
                    format!("failed to read an entry in `{}`", current.display())
                })?;
                stack.push(entry.path());
            }
            continue;

View on GitHub (pinned to 5176682b65)

Solutions

  1. Check the path exists before running: ls <path> or test -d <path>
  2. Use an absolute path or run the command from the intended working directory
  3. If the target is in a submodule, initialize it first with git submodule update --init --recursive

Example fix

# before
$ dbg-swc es flow strip --path ./submodules/flow  # not checked out yet
error: path does not exist: `./submodules/flow`

# after
$ git submodule update --init --recursive
$ dbg-swc es flow strip --path ./submodules/flow
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;

fn ensure_corpus_dir(path: &str) -> std::io::Result<&Path> {
    let p = Path::new(path);
    let meta = std::fs::metadata(p)?; // fails fast with a real io error if missing
    if !meta.is_dir() {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            format!("{path} is not a directory"),
        ));
    }
    Ok(p)
}

Type guard

import fs from 'node:fs';
const isUsablePath = (p: string): boolean => {
  try {
    return fs.statSync(p).isDirectory();
  } catch {
    return false;
  }
};

Prevention

When it happens

Trigger: Passing a --path that does not resolve: typo, relative path evaluated from a different cwd, deleted directory, or a path inside an uninitialized submodule.

Common situations: Running the CLI from a different working directory than assumed; copied commands with absolute paths from another machine; submodule mount points that exist only after 'git submodule update --init'.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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