No side effects on import
Why it matters
Code that executes at import time bypasses the consumer's control plane. A top-level fetch() fires before the consumer has configured anything; a top-level console.log pollutes test output and server logs; a globalThis mutation can conflict with other packages or the host environment. ISO 25010 compatibility and fault-tolerance both degrade when a package modifies global state the moment it's imported. In server-side rendering, side-effecting imports can crash the render pass. In test environments, they produce flaky behavior depending on import order.
Severity rationale
Critical because side effects on import execute before the consumer opts in, enabling silent global mutations, unsolicited network calls, and SSR crashes that are invisible until production.
Remediation
Move all initialization into exported constructors or factory functions. Nothing should run at module evaluation time.
// Before — side effects on import:
console.log('SDK loaded')
globalThis.__SDK = true
const config = await fetch('/api/config') // this fires on every import
// After — no side effects, consumer controls initialization:
export class Client {
constructor(private config: ClientConfig) {
// initialization here, when the consumer asks for it
}
}
Also declare in package.json:
{ "sideEffects": false }
This tells webpack, Rollup, and Vite that all modules are safe to tree-shake. If any files have legitimate side effects (CSS imports, polyfills), list only those files in the sideEffects array.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the SDK / Package Quality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · compatibility.interoperability — Interoperability — import-time side effects break SSR and test environments
- iso-25010:2011 · reliability.fault-tolerance — Fault tolerance — unexpected side effects on import cause failures in constrained environments
Taxons
History
- 2026-04-18·v1.0.0·Initial import from sdk-package-quality·automated