Deployment to PRODUCTION fails - tsc not found
Hello,
I have a very simple web application and using GitHub integration I deploy the code to our preview environment with no issues (NODE_ENV = development). However when I deploy to PROD (NODE_ENV = production) I get an error message during the build process as shown below.
16:30:15.623 Executing user command: bash build.sh
16:30:15.630 Executing WhichBnBN custom buid script
16:30:15.630 Build environment is PRODUCTION
16:30:16.199
16:30:16.199 > [email protected] build-prod 16:30:16.199 > tsc && vite build --mode production 16:30:16.199
16:30:16.211 sh: 1: tsc: not found 16:30:16.224 Failed: Error while executing user command. Exited with error code: 127 16:30:16.240 Failed: build command exited with code: 1 16:30:18.465 Failed: error occurred while running build command Anyone have any ideas why it works for dev and not for prod?
16:30:16.199 > [email protected] build-prod 16:30:16.199 > tsc && vite build --mode production 16:30:16.199
16:30:16.211 sh: 1: tsc: not found 16:30:16.224 Failed: Error while executing user command. Exited with error code: 127 16:30:16.240 Failed: build command exited with code: 1 16:30:18.465 Failed: error occurred while running build command Anyone have any ideas why it works for dev and not for prod?
9 Replies
It sounds like you have
tsc
/ vite
as devDependencies
. With NODE_ENV
set to production
, npm will not install dev dependencies, only production ones.That makes a lot of sense. I guess a follow up question is should I just copy all my devDependencies into my "dependencies" and see what happens Or is there a way of getting a list of dependencies needed for production?
I probably wouldn't set
NODE_ENV
at the build level, so that when npm installs, it gets all the deps it needs. I'd set it on the command level instead, so like NODE_ENV=production tsc && vite build --mode production
for exampleLet me make sure I understand. You are saying that I should remove the NODE_ENV variable from my Environment Variables? and then update my build script to set the environment variable NODE_ENV?
That would be my recommendation, yes
I dont see how that will change anything but I am definitely new to pipeline builds. Let me try and update back. Thank you for your suggestion.
When
npm install
(etc.) runs, if NODE_ENV
is set to production
, it doesn't install devDependencies
. Because you have this set as an environment variable, you're seeing this with tsc
and vite
, etc. not being installed
By moving that to the build command itself, tsc
and vite
will already be installed now so it won't impact them, but vite
and other packages will benefit from NODE_ENV=production
and be able to further optimise the build for productionOK after making that change the deployment to DEV (still) works. So thats good.
Now let me try the PROD build (which has not yet worked once)
You are a genius :-). Worked beautifully. thank you for your insight and for taking the time to answer my Noob question.
Happy to help, and glad it worked 😄