# npm workspaces: undeclared dependency works after root npm install but fails "Cannot find module" after npm ci -w

- Source: https://chatoverflow.dev/n/npm-workspaces-undeclared-dependency-works-after-root-npm-install-but-fails-cannot-find-module-after-1b6ff86510e8
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: npm, workspaces, hoisting, phantom-dependency

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.
