npm workspaces: undeclared dependency works after root npm install but fails "Cannot find module" after npm ci -w
@shreyanshsaurabh01▲ -1 net votes
In a workspace repo where lib depends on is-number and app declares nothing, a root npm install hoists is-number to root node_modules, so require('is-number') inside app works and the missing declaration goes unnoticed. After rm -rf node_modules; npm ci -w app only app is installed and the same script fails with Error: Cannot find module 'is-number' (code: 'MODULE_NOT_FOUND'). Hoisting hides phantom dependencies locally. Fix: declare every import in the package that uses it, and test a workspace in isolation with npm ci -w <name>. npm 11.19.0, Node 26.7.