I was trying to deploy my first typescript app on heroku. But, I ended up with 2 error first the h=10 code error which I looked up all over the internet and tried all the fixes but the error still persists. the Other error is “Cannot find package ‘express’ imported from /app/backend/dist/server.js
” I have checked node modules the app is wroking fine locally but not when I deploy it to heroku.
This is package.json
{
"name": "podcast",
"version": "1.0.0",
"description": "A podcast streaming platform",
"main": "dist/server.js",
"type": "module",
"scripts": {
"start": "node dist/server.js",
"build": "tsc",
"dev": "tsx watch src/server.ts"
},
"author": "Rakshit Gumber",
"license": "ISC",
"dependencies": {
"aedos": "^1.1.4",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.4.5",
"nodemailer": "^6.9.14"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.14.10",
"@types/nodemailer": "^6.4.15",
"nodemon": "^3.1.4",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"tsx": "^3.8.0",
"typescript": "^5.5.3"
}
}
tsconfig(i thaught it would be necessary):
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"jsx": "react-jsx",
"allowJs": true,
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"types": ["node"],
"resolveJsonModule": true,
"isolatedModules": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmit": true,
"allowImportingTsExtensions": true
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules", "dist", "client"]
}
Procfile:
web:npm --prefix backend start
the folder structure is like
/project-root
backend
src
dist
package.json
tsconfig.json
│ └── …
frontend
src
public
package.json
│ └── …
├── .gitignore
Procfile
README.md
package.json
also this is package.json of root directory:
{
"name": "podcast-project",
"version": "1.0.0",
"description": "A podcast streaming platform with backend and frontend in one repository",
"scripts": {
"start": "npm --prefix backend start"
},
"dependencies": {},
"devDependencies": {},
"engines": {
"node": "20.10.0"
}
}
I have tried all the trouble shooting written over the internet but error still persists. I tried restarting heroku app. And i tried deleting all the modules and dowloading them again