oven-sh/bun · error · Error

Could not find file ${filename} in $${fnName} call

Error message

Could not find file ${filename} in $${fnName} call

What it means

For non-rust native calls ($bindgenFn, $cpp, etc.), generate-js2native.ts resolves the filename by searching the scanned sourceFiles list for one whose path ends with the (platform-normalized) filename. This error means no known source file matches — the referenced file does not exist, is not part of the scanned set, or the path fragment is wrong. The message names the missing file and the call type so the bad call site is easy to find.

Source

Thrown at src/codegen/generate-js2native.ts:129

    throw new Error(`Expected filename for $${call_type} to have ${ext} extension, got ${JSON.stringify(filename)}`);
  }

  if (call_type === "rust") {
    const relative = rustIdentifierPaths[filename];
    if (!relative) {
      throw new Error(
        `Unknown $rust() file identifier ${JSON.stringify(filename)}. Add it to rustIdentifierPaths in src/codegen/generate-js2native.ts.`,
      );
    }
    return path.join(srcDir, relative.replaceAll("/", sep));
  }

  filename = filename.replaceAll("/", sep);

  const resolved = sourceFiles.find(file => file.endsWith(sep + filename));
  if (!resolved) {
    const fnName = call_type === "bind" ? "bindgenFn" : call_type;
    throw new Error(`Could not find file ${filename} in $${fnName} call`);
  }

  return filename;
}

export function registerNativeCall(
  call_type: NativeCallType,
  filename: string,
  symbol: string,
  create_fn_len: null | number,
) {
  const resolved_filename = resolveNativeFileId(call_type, filename);

  const maybe_wrapped_symbol = create_fn_len != null ? "js2native_wrap_" + symbol.replace(/[^A-Za-z]/g, "_") : symbol;

  const existing = nativeCalls.find(
    call =>
      call.is_wrapped == (create_fn_len != null) &&

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Verify the file actually exists at the path you intended (glob for the basename under src/)
  2. Correct the argument to a relative path that suffix-matches a real scanned source file, e.g. $bindgenFn("internal/streams/ReadableStream.cpp", "...")
  3. If the file is new, make sure it lives where the js2native scanner looks (sourceFiles) and re-run codegen
  4. On Windows, double-check slash direction in the fragment — the comparison uses path.sep

Example fix

// before
const fn = $bindgenFn("webcore/Responce.cpp", "jsResponseConstruct");

// after
const fn = $bindgenFn("webcore/Response.cpp", "jsResponseConstruct");
Defensive patterns

Strategy: validation

Validate before calling

// verify the fragment suffix-matches a real source file before registering
import path from "node:path";
import { Glob } from "bun";
function resolves(filename: string): boolean {
  const normalized = filename.replaceAll("/", path.sep);
  for (const f of new Glob("src/**/*.{cpp,h,ts}").scanSync(".")) {
    if (f.endsWith(path.sep + normalized)) return true;
  }
  return false;
}

Prevention

When it happens

Trigger: Passing a path fragment to $bindgenFn("...") / $cpp("...") that doesn't suffix-match any scanned file: a typo, a file that was renamed or deleted, or a wrong subdirectory prefix. Note separators are normalized to path.sep, so on Windows a leading-subdirectory mismatch (e.g. using '/' where the scan produced '\\') can also miss.

Common situations: Renames or directory moves under src/jsc/bindings leaving stale $bindgenFn references in .bind.ts files; new contributors guessing the expected path format (it must be a relative suffix like "webcore/Response.cpp", not absolute).

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/1bd9272487ca5097. Report an issue: GitHub.