Production Deployment Failing When Using CLI Package.json Scripts
I have created a basic application through the CLI tool (v6.3.0) and have reached the point where I was ready to push to a production server and came across an issue.
I am deploying using Shipit (which is probably not relevant) and part of this process is to install the npm dependencies (with the flag --production
).
Everything deploys without a hitch, until my deployment runs the final command npm run start:prod
(to start the Nest application on the node process). Which executes the following steps:
- Deletes the contents of the dist directory
rimraf dist && npm run build
; - Tries to rebuild the contents of the dist directory
tsc -p tsconfig.build.json
; - Runs
node dist/main.js
;
The problem with all this, is that the TypeScript
package that I believe provides the tsc
command is a devDependency not a dependency that is installed during npm install with the --production
flag.
Is this a bug, or am I completely missing the point of the npm run start:prod
command. I appreciate that installing the TypeScript package globally may resolve the issue, although I wasn't sure if that was the intention, or assumption?
If you deploy NestJS to production, are you utilising some other strategy?
Answer
In server-side applications the distinction between dependencies
and devDependencies
is not as important, since you're not shipping your dependencies and hence a the size of your application is not as critical.
However, when you deploy to the cloud you might want to save space. TypeScript is not needed to run your application once it is compiled. And you don't need to recompile your application when you simply want to restart it. So, what you could do instead:
Remove the prestart:prod
script.
Deployment routine:
- Install all dependencies with
npm install
- Run
npm run build
- Prune your dev dependencies with
npm prune --production
- Run
npm run start:prod
This is pretty much what happens when I deploy to heroku.
Alternatively, you can of course declare typescript
under dependencies
instead of devDependencies
.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM