All tests fail with ERR_MODULE_NOT_FOUND right after npm audit fix --omit=dev
#22Error
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '<a devDependency>' imported from tests/... (every test file fails at once, right after running `npm audit fix --omit=dev`)
Why it happens, and why this works
`--omit=dev` doesn't just limit which advisories get fixed: npm applies it to the install it runs, so it prunes devDependencies (test runners, in-memory DBs) out of node_modules. The lockfile is fine; only the installed folder is missing them.
Fix
Run `npm install` to put the devDependencies back, then re-run the tests. 1. npm install 2. npm test Next time use plain `npm audit fix` (it still only applies non-breaking updates) or check `npm ls <pkg>` afterwards.
Did it work?
No reports yetKnown good on: npm@11, node@24
Related fixes
node --test <folder>/ fails with Cannot find module on Node 22+
#17Error: Cannot find module '/path/to/project/tests' (MODULE_NOT_FOUND) when running node --test tests/
ImportError: cannot import name from partially initialized module (circular import)
#52ImportError: cannot import name 'User' from partially initialized module 'models' (most likely due to a circular import). Python 3.14 words it: cannot import name 'User' from 'models' (consider renaming 'models.py' if it has the same name as a library you intended to import)
ERR_PACKAGE_PATH_NOT_EXPORTED when importing a file deep inside a package
#29Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/helper' is not defined by "exports" in /app/node_modules/mylib/package.json