I’m trying to deploy my first app to Heroku Per the documentation, Heroku build phase should install the devDependencies, right? But it always fail with tsc not found
I even tried to add typescript
as a dependency, not devDependency, the tsc worked during the build phase, but the frontend failed due to the @types/react
not installed It should work and I’m not sure why it’s not working
I have this structure currently:
- backend
-- package.json
-- src
- frontend
-- package.json
-- src
- build (this is in .gitignore and contains both backend and frontend builds)
- package.json
- Procfile
In my root package.json, I have:
{
...
"scripts": {
"test": "jest",
"start": "cd build/backend/src && node index.js",
"build": "cd frontend && yarn install && cd ../backend && yarn install"
},
...
}
my Procfile: web: yarn start
backend package.json:
{
...
"scripts": {
"postinstall": "yarn run build",
"build": "tsc --build --verbose && tsc-alias",
"postbuild": "cp package.json ../build/backend/package.json && cp .env ../build/backend || : && cd ../build/backend && yarn install --prod",
"start": "ts-node-dev -r tsconfig-paths/register --project ./tsconfig.json ./src/index.ts --diagnostics --ignore-watch node_modules",
"test": "jest"
},
"devDependencies": {
...
"tsc-alias": "^1.8.10",
"typescript": "^5.0.4"
...
}
...
}
and my frontend package.json:
{
...
"scripts": {
"postinstall": "yarn run build",
"start": "vite",
"build": "tsc --build --verbose && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"devDependencies": {
...
"@types/react": "^18.3.3",
"typescript": "^5.2.2"
...
}
...
}
[EDIT]
Got it working by with this workaround on my root package.json, I’m not sure if this is the best option
{
...
"scripts": {
"test": "jest",
"start": "cd build/backend/src && node index.js",
"postinstall": "cd frontend && yarn install --production=false && cd ../backend && yarn install --production=false",
"build": "cd frontend && yarn build && cd ../backend && yarn build"
},
...
}