I ran into a problem when deploying my Express app on Render:
Cannot find module '/opt/render/project/src/server/dist/db/connect' imported from /opt/render/project/src/server/dist/server.js
My settings:
Root directory: server
Build command: server/ $
(added automatically) npm install; npm run build && ls dist/db
Start command: server/ $
(added automatically) npm start
.
What I’ve tried:
- added
ls dist/db
to specifically check the existence of the file in question, and it does exist (see left screenshot); - checked the casing of the file names;
- checked the paths;
tsconfig.ts:
{
"compilerOptions": {
"target": "es2016",
"moduleResolution": "node",
"allowJs": true,
"outDir": "./dist",
"esModuleInterop": true
"forceConsistentCasingInFileNames": true,
"strict": false,
"skipLibCheck": true
}
}
package.json:
{
"main": "server.ts",
"engines": {
"node": ">=20.11.1"
},
"scripts": {
"dev": "nodemon server.ts",
"build": "tsc",
"start": "node dist/server.js"
},
"type": "module",
(...)
I import the file like this:
server.js:
import connectDB from './db/connect';
My file structure inside the root directory is on the right screenshot.
I’d be grateful if someone could help me with my issue.