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?
9 Replies
James
James•7mo ago
It sounds like you have tsc / vite as devDependencies. With NODE_ENV set to production, npm will not install dev dependencies, only production ones.
nat20sFruitBat07Dad
nat20sFruitBat07Dad•7mo ago
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?
James
James•7mo ago
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 example
nat20sFruitBat07Dad
nat20sFruitBat07Dad•7mo ago
Let 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?
James
James•7mo ago
That would be my recommendation, yes
nat20sFruitBat07Dad
nat20sFruitBat07Dad•7mo ago
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.
James
James•7mo ago
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 production
nat20sFruitBat07Dad
nat20sFruitBat07Dad•7mo ago
OK 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.
James
James•7mo ago
Happy to help, and glad it worked 😄
Want results from more Discord servers?
Add your server