Skip to main content

SKY-Q408 · Quality, structure and performance

Undeclared npm dependency

Medium

A literal source import, type reference or supported configuration use names an npm package that neither the owning package.json nor an ancestor workspace declares. With strict_dependencies = true, production source of a published package needs its own declaration.

Languages
TypeScript, JavaScript, package.json
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
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The source may work only because a different workspace or a transitive dependency happened to install the package. A clean install or dependency upgrade can then fail.

What Skylos flags

package.json · JSON
{"name":"shop","version":"1.0.0","main":"src/app.js","dependencies":{}}
src/app.js · JavaScriptReported on line 1
import "chalk";

What Skylos leaves alone

package.json · JSON
{"name":"shop","version":"1.0.0","dependencies":{"chalk":"^5.0.0"}}

src/app.js: same as in the flagged example.

Why Skylos leaves it alone

The owning manifest explicitly declares the imported package.

How Skylos decides

  1. Runs with quality analysis and reads package manifests without installing packages or running package scripts.
  2. Assigns source files to their nearest package.json; a nested one that declares no name, dependencies, workspaces, scripts or binaries (a marker holding only type) does not own files. Reads literal imports, re-exports, require/import calls, /// <reference types> directives, tsconfig types entries and supported literal tool configuration, including Vue, Svelte and Astro script blocks and top-level MDX ESM (fenced code and prose are ignored). Built-ins, local paths, proven workspace aliases and framework module aliases such as Docusaurus @theme/* are excluded.
  3. Node resolution walks up to ancestor node_modules, so an ancestor workspace's declaration satisfies every file below it by default; the receipt counts published production imports that rely on one (ancestor_declared_production_imports). With [tool.skylos] strict_dependencies = true published production source needs its own declaration and the finding names the ancestor_manifest. A sibling workspace's declaration never counts.
  4. A workspace package that tsconfig paths or a readable bundler alias maps to project source is not reported outside published production source. Fixture text that codemod harnesses read (__testfixtures__/, __fixtures__/, fixtures/**/input.*/output.*) and JSDoc import() types outside published production source are usage evidence only. A type-only import is satisfied by the matching @types/ declaration.
  5. Stylesheets are usage evidence only, except unambiguous package references (Sass pkg:name URLs and Tailwind @plugin names); a bare CSS @import can be a local file or load path and is never reported.
  6. Checks dependencies, devDependencies, optionalDependencies and peerDependencies in the owner. Reports MEDIUM at the source or configuration use when its package is missing.
  7. Does not claim that the registry package exists or that an SDK API is valid. Unknown loaders and unread source are recorded in analysis_summary.npm_dependency_analysis and cannot prove dependency non-use.

How to fix it

Declare the intended package in the manifest that owns the source, using an appropriate dependency section and version, or remove the unwanted import.

package.json · JSON · the fix, against the flagged file
Removed: {"name":"shop","version":"1.0.0","main":"src/app.js","dependencies":{}}Added: {"name":"shop","version":"1.0.0","dependencies":{"chalk":"^5.0.0"}}

When it can be wrong

  • A deployment may deliberately provide an undeclared package globally; the repository alone does not declare that contract.
  • A published package's production file that is never shipped (excluded from files or the build) is still treated as published source.
  • Only bounded literal source/configuration forms are read. Unknown configuration is recorded rather than executed.

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

  • Set [tool.skylos] ignore = ["SKY-Q408"] to disable this rule project-wide.

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