SKY-Q413 · Quality, structure and performance
Referenced optional peer dependency
A package marks a peer dependency optional in peerDependenciesMeta, but its own source imports that peer with a static runtime import. The package lists it in neither dependencies nor devDependencies.
- 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
Why it matters
Consumers may legitimately skip an optional peer. A static import then fails when the module loads, so the optional contract is broken for exactly those consumers.
What Skylos flags
{ "name": "ui-kit", "peerDependencies": {"react": "^18.0.0"}, "peerDependenciesMeta": {"react": {"optional": true}}}import React from "react";export const version = React.version;What Skylos leaves alone
export async function loadReact() { try { return await import("react"); } catch { return null; }}Why Skylos leaves it alone
The optional peer is loaded lazily, and the caller handles its absence.
How Skylos decides
- Reads peerDependencies and peerDependenciesMeta from the owning package.json, ignoring a peer that is also in dependencies or devDependencies.
- Considers only static runtime import and export-from declarations in owned sources, components and MDX. Type-only imports, declaration files and dynamic import or require calls stay quiet.
- Reports LOW once per peer at its first import. Packages with subpath exports are skipped, because a framework-specific entry point may require the peer; the receipt lists them under optional_peer_limitations.
How to fix it
Load the peer lazily and handle its absence, move the import to a subpath entry point, or make the package a regular dependency.
Removed: import React from "react";Removed: export const version = React.version;Added: export async function loadReact() {Added: try {Added: return await import("react");Added: } catch {Added: return null;Added: }Added: }When it can be wrong
- A module that is only ever loaded by consumers that install the peer (for example through a deep import path) is still reported when the package has no subpath exports.
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-Q413"]to disable this rule project-wide.Put the marker on the reported import line.
TypeScript import React from "react"; // skylos: ignore[SKY-Q413] only loaded by React consumers