Dev dependencies used in production
What a dev-dependency-in-production finding of fallow dead-code means, why it matters and how to fix it.
What it reports
devDependency imported by production code with a runtime import.
Dependencies explains how fallow finds it.
Why it matters
A package in devDependencies that is imported by production (non-test, non-config) source code via a runtime/value import. Whether it should be promoted to dependencies depends on the deployment: a production-only install (pnpm install --prod) omits devDependencies, so an import resolved at runtime breaks, while a build that inlines the package into its output resolves nothing at runtime and promoting it can instead make the deployment require an install it did not need. This is the promote-side mirror of test-only-dependency and type-only-dependency. A dev dependency imported from production code only via import type is not flagged (types are erased at build time), and a package also listed in dependencies, peerDependencies, or optionalDependencies is left alone because another manifest section provides it at runtime.
Example
yaml is in devDependencies, but src/config.ts imports { parse } from 'yaml' and runs it at runtime.
Fix
Move the package to dependencies when the deployment installs them, so a production-only install keeps it. Leave it in devDependencies if the build inlines it into the output, if the only production imports are import type, or if another manifest section (dependencies / peer / optional) already provides it.
Facts
| Fact | Value |
|---|---|
| Issue type | dev-dependency-in-production |
| Rule id in SARIF output | fallow/dev-dependency-in-production |
| Command | fallow dead-code |
| Default severity | warn |
Config key in rules | dev-dependencies-in-production |
| Filter option | --unused-deps |
Fixable with fallow fix | No |
| Opt-in | No |
When to keep the code
- The build puts the package into its output, so the deployment does not install it.
- A tool script imports the package. Add the script to
supportEntry. Fallow then does not count its imports as production imports.
Notes
The finding points at a line of package.json, which cannot hold a comment. To keep one package, add it to ignoreDependencies. A rule in overrides has no effect on this issue type.