Cannot find module 'express' or its corresponding type declarations.
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/src/utils'
This error has several different causes depending on whether youβre in TypeScript, Node.js, or both.
Fix 1: Package Not Installed
# Install the package
npm install express
# For TypeScript, you might also need types
npm install -D @types/express
Check if itβs in your package.json. If you cloned a repo, run npm install first.
Fix 2: Missing File Extension (Node.js ESM)
Node.js with ES modules requires file extensions in imports:
// β Node ESM won't resolve this
import { helper } from './utils';
// β
Add the extension
import { helper } from './utils.js';
Yes, even for TypeScript files β you import .js even though the source is .ts. TypeScript compiles .ts β .js, so the import needs to match the output.
Fix 3: TypeScript Path Issues
// tsconfig.json β check these settings
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"moduleResolution": "bundler", // or "node16" for Node.js
"module": "ESNext"
}
}
If youβre using path aliases (@/utils), make sure both TypeScript AND your bundler/runtime know about them.
Fix 4: Missing Type Declarations
Could not find a declaration file for module 'some-package'.
# Try installing types
npm install -D @types/some-package
If types donβt exist, create a declaration file:
// src/types/some-package.d.ts
declare module 'some-package';
Fix 5: Wrong moduleResolution
// tsconfig.json
{
"compilerOptions": {
// For bundlers (Vite, Webpack, Next.js):
"moduleResolution": "bundler",
// For Node.js:
"moduleResolution": "node16",
// β Avoid "node" (legacy) for new projects
}
}
Fix 6: node_modules Corrupted
Nuclear option β delete and reinstall:
rm -rf node_modules package-lock.json
npm install
Quick Diagnosis
# Check if the package exists
ls node_modules/express
# Check TypeScript can find it
npx tsc --noEmit
# Check Node.js can find it
node -e "require('express')"