{"record":{"id":"bb4435a37cbc2dac","repo":"swc-project/swc","slug":"file-not-found","errorCode":null,"errorMessage":"file not found: {}","messagePattern":"file not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_loader/src/resolvers/node.rs","lineNumber":230,"sourceCode":"                    // \".tsx\" even if the original extension was \".jsx\".\n                    \"js\" => &[\"ts\", \"tsx\"],\n                    \"jsx\" => &[\"ts\", \"tsx\"],\n                    \"mjs\" => &[\"mts\"],\n                    \"cjs\" => &[\"cts\"],\n                    _ => &[],\n                };\n\n                for ext in extensions {\n                    ext_path.set_extension(ext);\n\n                    if ext_path.is_file() {\n                        return Ok(Some(ext_path));\n                    }\n                }\n            }\n        }\n\n        bail!(\"file not found: {}\", path.display())\n    }\n\n    /// Resolve a path as a directory, using the \"main\" key from a package.json\n    /// file if it exists, or resolving to the index.EXT file if it exists.\n    fn resolve_as_directory(\n        &self,\n        path: &Path,\n        allow_package_entry: bool,\n    ) -> Result<Option<PathBuf>, Error> {\n        #[cfg(debug_assertions)]\n        let _tracing = if cfg!(debug_assertions) {\n            Some(\n                tracing::span!(\n                    Level::TRACE,\n                    \"resolve_as_directory\",\n                    path = tracing::field::display(path.display())\n                )\n                .entered(),","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_loader/src/resolvers/node.rs#L212-L248","documentation":"NodeResolver::resolve_as_file bails with this error after every candidate for a path fails. Candidates are: the exact path if it already has an extension, `<path>.js`, the raw path itself, then every extension in EXTENSIONS, plus TypeScript-style substitution (.js/.jsx -> .ts/.tsx, .mjs -> .mts, .cjs -> .cts). So the specifier looked like a file but no file with any recognized extension exists at that location.","triggerScenarios":"An import (or require) of a relative/absolute specifier that does not exist on disk in any of the resolver's supported extensions, e.g. './missing-module', './config.json5' when the file is absent, or './foo.js' when only a sibling with an extension outside the substitution table exists.","commonSituations":"Typos in import paths after a rename/move refactor; case-sensitivity mismatches working on Windows then building on Linux; importing files with unsupported extensions (e.g. '.vue', '.svelte') through NodeResolver without a custom extension handling or plugin; missing files in a shallow git checkout/submodule.","solutions":["Verify the exact file exists on disk (watch out for case sensitivity and stale builds); fix the import path or restore the file","For '.js' imports in TypeScript projects, confirm the corresponding '.ts'/'.tsx' file exists (the resolver only substitutes those)","If you need custom extensions, wire a custom resolver/transform in the loader pipeline instead of relying on NodeResolver defaults","Run git submodule update --init --recursive if the path lives in a submodule not checked out"],"exampleFix":"// before\nimport { x } from './util/helper'; // no helper.ts on disk\n\n// after (file is helper/index.ts)\nimport { x } from './util/helper/index';\n// or create the missing ./util/helper.ts","handlingStrategy":"try-catch","validationCode":"// Pre-check that some candidate file exists for a relative specifier\nimport { existsSync } from 'node:fs';\nconst EXTS = ['', '.js', '.ts', '.tsx', '.mjs', '.cjs', '.jsx', '.mts', '.cts'];\nconst resolvable = (p) => EXTS.some((e) => existsSync(p + e));","typeGuard":null,"tryCatchPattern":"try {\n  const resolved = resolver.resolve(base, spec);\n} catch (e) {\n  if (e.message.startsWith('file not found')) throw new Error(`Cannot resolve '${spec}' from ${base}: check the path, extension, and case`);\n  throw e;\n}","preventionTips":["Run typecheck (tsc --noEmit) before bundling to catch broken relative imports early","Watch for case-sensitivity issues when builds move from macOS/Windows to Linux","Keep file renames and import updates in the same commit; lint with import/no-unresolved"],"tags":["module-resolution","node-resolver","file-not-found","swc-ecma-loader","import"],"backgroundTag":"module-not-found","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}