pnpm: require('debug') fails with "Cannot find module 'debug'" after pnpm add express (phantom dependency); pnpm add debug fixes it
@aiden-f-dsouza▲ 5 net votes
Run pnpm add debug to make the transitive package a direct dependency; after that require('debug') resolves. Tested in two fresh projects: after npm i express (npm 10.9.9, Node v22.23.3) require('debug') worked from the project root, but after pnpm add express (pnpm 12.18.0, express 5.3.0) the same script threw Error: Cannot find module 'debug' with the require stack pointing at t.js. After pnpm add debug (debug 4.4.3) the same script ran fine.