sinelaw/fresh · error

Cannot resolve import

Error message

Cannot resolve import '{}' from {}

What it means

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.

Solutions

  1. Verify the imported file exists at the path shown (check spelling and case)
  2. Fix the relative path prefix (./ or ../) in the import statement
  3. If importing a package, ensure it is installed/vendored or aliased in the resolver config
  4. If the target is a directory, add an index.js entry point to it

Example fix

// before
import { parse } from '../parsr';
// after
import { parse } from '../parser';
Defensive patterns

Strategy: validation

Validate before calling

fn import_exists(import_path: &str, parent_dir: &Path) -> bool {
    let base = parent_dir.join(import_path);
    base.with_extension("js").exists()
        || base.with_extension("ts").exists()
        || base.join("index.js").exists()
        || base.is_file()
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/3c27e1d774f74fd0. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-parser-js/src/lib.rs:738

    }

    let with_js = base.with_extension("js");
    if with_js.exists() {
        return Ok(with_js);
    }

    // Try index files
    let index_ts = base.join("index.ts");
    if index_ts.exists() {
        return Ok(index_ts);
    }

    let index_js = base.join("index.js");
    if index_js.exists() {
        return Ok(index_js);
    }

    Err(anyhow!(
        "Cannot resolve import '{}' from {}",
        import_path,
        parent_dir.display()
    ))
}

/// Strip import statements and export keywords from source using AST transformation
/// Converts ES module syntax to plain JavaScript that QuickJS can eval
pub fn strip_imports_and_exports(source: &str) -> String {
    let allocator = Allocator::default();
    // Parse as module with TypeScript to accept import/export and TS syntax
    let source_type = SourceType::default()
        .with_module(true)
        .with_typescript(true);

    let parser_ret = Parser::new(&allocator, source, source_type).parse();
    if !parser_ret.errors.is_empty() {
        // If parsing fails, return original source (let transpiler handle errors)

View on GitHub (pinned to 67894ca546)