After some debugging, I realized that the issue was due to devDependencies
being skipped when NODE_ENV=production
is set — which is the default in Render. As a result, tools like typescript
and @types/node
were missing during the build step, causing the tsc
command to fail with this error:
error TS2688: Cannot find type definition file for 'node'
What ended up working was the following:
in the package.json
, I left the build script as simply:
"build": "tsc"
then, in Render’s Build Command, I changed it to:
npm install --include=dev && npm run build
the Start Command remains unchanged:
npm start
This ensures that the dev dependencies are available only during the build phase (when tsc runs), and not included at runtime and finally the application works as expected.
That said, it raised a question for me: isn't the purpose of devDependencies to not be included in production environments? by forcing them to install with --include=dev, I’m breaking that convention a bit. Is this acceptable when the build and production environments are merged (as with Render), or is there a cleaner approach?