{"record":{"id":"3c27e1d774f74fd0","repo":"sinelaw/fresh","slug":"cannot-resolve-import-from","errorCode":null,"errorMessage":"Cannot resolve import '{}' from {}","messagePattern":"Cannot resolve import '(.+?)' from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-parser-js/src/lib.rs","lineNumber":738,"sourceCode":"    }\n\n    let with_js = base.with_extension(\"js\");\n    if with_js.exists() {\n        return Ok(with_js);\n    }\n\n    // Try index files\n    let index_ts = base.join(\"index.ts\");\n    if index_ts.exists() {\n        return Ok(index_ts);\n    }\n\n    let index_js = base.join(\"index.js\");\n    if index_js.exists() {\n        return Ok(index_js);\n    }\n\n    Err(anyhow!(\n        \"Cannot resolve import '{}' from {}\",\n        import_path,\n        parent_dir.display()\n    ))\n}\n\n/// Strip import statements and export keywords from source using AST transformation\n/// Converts ES module syntax to plain JavaScript that QuickJS can eval\npub fn strip_imports_and_exports(source: &str) -> String {\n    let allocator = Allocator::default();\n    // Parse as module with TypeScript to accept import/export and TS syntax\n    let source_type = SourceType::default()\n        .with_module(true)\n        .with_typescript(true);\n\n    let parser_ret = Parser::new(&allocator, source, source_type).parse();\n    if !parser_ret.errors.is_empty() {\n        // If parsing fails, return original source (let transpiler handle errors)","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-parser-js/src/lib.rs#L720-L756","documentation":"resolve_import in the JS parser could not map an import specifier to an actual file on disk. It tries extension substitutions and index.js resolution under the importing file's directory; when no candidate file exists it fails with this error naming the import path and the parent directory.","triggerScenarios":"A module imports './foo' (or a bare path) but no foo.ts/js/index.js exists at the expected location; imports of bare npm package specifiers that aren't vendored/aliased; wrong relative depth ('../' too few/many) in the import path.","commonSituations":"Renamed or deleted a file without updating importers; case-mismatched filenames on case-sensitive filesystems; plugin project missing an index.js entry file; npm dependencies not installed/vendored when parsing.","solutions":["Verify the imported file exists at the path shown (check spelling and case)","Fix the relative path prefix (./ or ../) in the import statement","If importing a package, ensure it is installed/vendored or aliased in the resolver config","If the target is a directory, add an index.js entry point to it"],"exampleFix":"// before\nimport { parse } from '../parsr';\n// after\nimport { parse } from '../parser';","handlingStrategy":"validation","validationCode":"fn import_exists(import_path: &str, parent_dir: &Path) -> bool {\n    let base = parent_dir.join(import_path);\n    base.with_extension(\"js\").exists()\n        || base.with_extension(\"ts\").exists()\n        || base.join(\"index.js\").exists()\n        || base.is_file()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use editor tooling (rust-analyzer/tsserver) to catch unresolved imports early","Keep file renames and import updates in the same commit","Pin and vendor npm dependencies before parsing","Watch filename case on case-sensitive filesystems"],"tags":["module-resolution","filesystem","javascript"],"backgroundTag":"resource-not-found","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}