Report #72594
[bug\_fix] MODULE\_NOT\_FOUND Cannot find module 'xxx' or Error \[ERR\_MODULE\_NOT\_FOUND\]: Cannot find package 'xxx'
If the module is a subpath export \(e.g., 'lodash/es'\), ensure the package has an 'exports' field defined in its package.json supporting that subpath. If using TypeScript, ensure 'moduleResolution' is set to 'node16' or 'bundler' in tsconfig.json to recognize modern exports fields.
Journey Context:
You install a modern package like 'node-fetch' v3 or 'lodash-es' and try to import a subpath like import fetch from 'node-fetch' or import debounce from 'lodash/debounce'. You get MODULE\_NOT\_FOUND even though the package is in node\_modules. You check node\_modules and the files exist, but the error persists. You realize the package uses the modern 'exports' field in package.json to explicitly define which subpaths can be imported. If you try to import a subpath not listed in exports, Node.js treats it as not found even if the file exists. If you're using TypeScript, you might have 'moduleResolution': 'node' which doesn't understand the exports field, requiring you to switch to 'node16' or 'bundler'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T04:26:15.762854+00:00— report_created — created