Skip to main content

SKY-Q414 · Quality, structure and performance

Unresolved import

Medium

A literal relative import, or one that matches a tsconfig paths alias or a package.json imports key, names no file in the project. Extensions, index files, TypeScript source for .js specifiers and directory package.json files have all been tried.

Languages
TypeScript, JavaScript, Vue, Svelte, Astro
Turned on by
skylos . --quality
Quality gate
counted toward the gate limits (full and diff scans). Reported as quality; counts toward max_quality.
Finding type
defect
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The build or the first run of the importing module fails with a module-not-found error. A renamed or deleted file usually leaves such imports behind.

What Skylos flags

package.json · JSON
{"name":"shop","version":"1.0.0"}
src/formatting.ts · TypeScript
export const price = (cents: number) => (cents / 100).toFixed(2);
src/index.ts · TypeScriptReported on line 1
import { price } from "./format";console.log(price(1999));

What Skylos leaves alone

package.json: same as in the flagged example.

src/formatting.ts: same as in the flagged example.

src/index.ts · TypeScript
import { price } from "./formatting.js";console.log(price(1999));

Why Skylos leaves it alone

The .js specifier maps to the TypeScript source formatting.ts, as tsc and bundlers resolve it.

How Skylos decides

  1. Runs with quality analysis on literal import, export ... from, require() and import() requests in scanned JS/TS files and in Vue, Svelte and Astro script blocks. Type-only imports are erased at build time and left to the type checker; bare package names are SKY-Q408's concern; config files are parsed, never executed.
  2. Tries the exact path, source, declaration, component and data extensions, platform variants, .js to TypeScript source, index files, a directory package.json and tsconfig rootDirs. An alias is tried through every mapped target, with build output mapped to source.
  3. Stays quiet for query or loader suffixes, virtual modules (virtual:, astro:, ~icons/, $app/, $env/), loads in a try body or with .catch, ambient declare module names, prefixes aliased by a JS bundler config (an unreadable alias holds back every alias below it), targets in node_modules, outside the project, excluded or Git-ignored, fixture, snapshot and template directories, unimported non-test files under test directories, and aliases under a tsconfig extending a generated config that is missing.
  4. Reports MEDIUM at the import line. analysis_summary.unresolved_import_analysis counts the requests checked and why others were held back.

How to fix it

Point the import at the file that exists, restore the missing file, or remove the import.

src/index.ts · TypeScript · the fix, against the flagged file
Removed: import { price } from "./format";Added: import { price } from "./formatting";console.log(price(1999));

When it can be wrong

  • A file produced by a build step that is neither Git-ignored nor in an excluded directory is missing from a clean checkout and is reported.
  • Aliases defined only in code Skylos does not read (a plugin computing aliases, a tsconfig other than the nearest tsconfig.json) are not recognised, so their imports are not checked.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Add // skylos: ignore[SKY-Q414] to the import line to accept one import.

    TypeScript
    import { price } from "./format"; // skylos: ignore[SKY-Q414] generated in CI
  • Set [tool.skylos] ignore = ["SKY-Q414"] to disable this rule project-wide.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.