{"record":{"id":"1bd9272487ca5097","repo":"oven-sh/bun","slug":"could-not-find-file-filename-in-fnname-call","errorCode":null,"errorMessage":"Could not find file ${filename} in $${fnName} call","messagePattern":"Could not find file (.+?) in \\$(.+?) call","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-js2native.ts","lineNumber":129,"sourceCode":"    throw new Error(`Expected filename for $${call_type} to have ${ext} extension, got ${JSON.stringify(filename)}`);\n  }\n\n  if (call_type === \"rust\") {\n    const relative = rustIdentifierPaths[filename];\n    if (!relative) {\n      throw new Error(\n        `Unknown $rust() file identifier ${JSON.stringify(filename)}. Add it to rustIdentifierPaths in src/codegen/generate-js2native.ts.`,\n      );\n    }\n    return path.join(srcDir, relative.replaceAll(\"/\", sep));\n  }\n\n  filename = filename.replaceAll(\"/\", sep);\n\n  const resolved = sourceFiles.find(file => file.endsWith(sep + filename));\n  if (!resolved) {\n    const fnName = call_type === \"bind\" ? \"bindgenFn\" : call_type;\n    throw new Error(`Could not find file ${filename} in $${fnName} call`);\n  }\n\n  return filename;\n}\n\nexport function registerNativeCall(\n  call_type: NativeCallType,\n  filename: string,\n  symbol: string,\n  create_fn_len: null | number,\n) {\n  const resolved_filename = resolveNativeFileId(call_type, filename);\n\n  const maybe_wrapped_symbol = create_fn_len != null ? \"js2native_wrap_\" + symbol.replace(/[^A-Za-z]/g, \"_\") : symbol;\n\n  const existing = nativeCalls.find(\n    call =>\n      call.is_wrapped == (create_fn_len != null) &&","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-js2native.ts#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Verify the file actually exists at the path you intended (glob for the basename under src/)","Correct the argument to a relative path that suffix-matches a real scanned source file, e.g. $bindgenFn(\"internal/streams/ReadableStream.cpp\", \"...\")","If the file is new, make sure it lives where the js2native scanner looks (sourceFiles) and re-run codegen","On Windows, double-check slash direction in the fragment — the comparison uses path.sep"],"exampleFix":"// before\nconst fn = $bindgenFn(\"webcore/Responce.cpp\", \"jsResponseConstruct\");\n\n// after\nconst fn = $bindgenFn(\"webcore/Response.cpp\", \"jsResponseConstruct\");","handlingStrategy":"validation","validationCode":"// verify the fragment suffix-matches a real source file before registering\nimport path from \"node:path\";\nimport { Glob } from \"bun\";\nfunction resolves(filename: string): boolean {\n  const normalized = filename.replaceAll(\"/\", path.sep);\n  for (const f of new Glob(\"src/**/*.{cpp,h,ts}\").scanSync(\".\")) {\n    if (f.endsWith(path.sep + normalized)) return true;\n  }\n  return false;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass paths relative to src/ (e.g. \"webcore/Response.cpp\") — never absolute paths or bare basenames that can collide","After renaming or moving a binding source, grep .bind.ts files for the old path fragment"],"tags":["codegen","bindings","js2native","file-resolution"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}