R
Railway6mo ago
Chioma

Deploying Angular App - "Nixpacks build failed" Error

Hi! I am hoping someone can help me please. I am trying to deploy an Angular App. I have done this before, and I received amazing help here, so I am trying to go about it the same way, referencing that thread (https://discord.com/channels/713503345364697088/1150242012851880090). However the error I am getting now is something I haven't seen before, so I was hoping for some guidance. I attached a screenshot error. I also have one follow up question related to all of this, but I am hoping to focus on this first please. Thanks in advance! GitHub: https://github.com/ChiomaGrace/AngularApp/tree/main Note: I am able to use railway locally (npm run start for frontend) (railway run npm run start for back end), and it works fine
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
GitHub
GitHub - ChiomaGrace/AngularApp
Contribute to ChiomaGrace/AngularApp development by creating an account on GitHub.
133 Replies
Percy
Percy6mo ago
Project ID: N/A
Chioma
Chioma6mo ago
N/A
Brody
Brody6mo ago
the package.json in your backend is missing a start script
Chioma
Chioma6mo ago
Hi again, Brody! Oh okay, so I just need to add this:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
is that right?
Brody
Brody6mo ago
looks like it could work
Chioma
Chioma6mo ago
Okay I am trying now It deployed, but the site isn't up
Brody
Brody6mo ago
is your app listening on PORT?
Chioma
Chioma6mo ago
I changed it to this:
Brody
Brody6mo ago
looks good, do you have the root directory on the service set to /backend
Chioma
Chioma6mo ago
yes!
Brody
Brody6mo ago
send the link to the backend?
Brody
Brody6mo ago
I get a not found, that's not a bad thing, just means you don't have anything registered for the route path
Chioma
Chioma6mo ago
ah. that makes sense. i don't think i have my angular service going to my backend yet so that checks i have one more question if that's okay
Brody
Brody6mo ago
of course
Chioma
Chioma6mo ago
Can you help explain to me why this is happening locally please?
Brody
Brody6mo ago
you have something else running on port 8000
Chioma
Chioma6mo ago
I found a fix: But I don't get why it says I have two things running on port 8000 i have two terminals. one i am running in the front end and one for the back end. but that's it
Brody
Brody6mo ago
is the frontend running on port 8000 too?
Chioma
Chioma6mo ago
i don't think so, but I guess I don't understand how to check? I thought angular ran on 4200
Brody
Brody6mo ago
well something else is running on that port, I have no way to tell you what though
Chioma
Chioma6mo ago
it shows me the two things: is it because i did this?
Brody
Brody6mo ago
no cors doesn't have anything to do with this
Chioma
Chioma6mo ago
okay cool but yeah this is how i'm running my front end terminal then my back end terminal i get that error:/
Brody
Brody6mo ago
very strange but I'm sorry I don't know as I have no way of telling you what's running
Chioma
Chioma6mo ago
right! and that's okay thanks for helping out again! happy holidays:)
Brody
Brody6mo ago
no problem, happy holidays to you too!
Chioma
Chioma6mo ago
sorry i'm back again i understand the backend url now, but shouldn't the front end url work though?
Brody
Brody6mo ago
send the frontend url please
Chioma
Chioma6mo ago
angular-app-frontend-production.up.railway.app
Brody
Brody6mo ago
build logs of that please
Chioma
Chioma6mo ago
do i give u the id for that?
Chioma
Chioma6mo ago
Railway
404 - Page not found
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Brody
Brody6mo ago
I don't work for railway so no I don't have access to that
Chioma
Chioma6mo ago
can you remind me how to share the log w you again please? Here's my deployment id: d6495021-8106-45ab-923a-8c666c5cd20b not sure if that's helpful
Brody
Brody6mo ago
https://bookmarklets.up.railway.app/log-downloader/ IDs don't help me since I don't work for Railway
Chioma
Chioma6mo ago
Brody
Brody6mo ago
angular 16 or 17?
Chioma
Chioma6mo ago
17
Brody
Brody6mo ago
https://github.com/railwayapp-templates/angular-starter/tree/main copy the nixpacks.toml and Caddyfile from this repo into your frontend
Chioma
Chioma6mo ago
okay adding now that did the trick!
Brody
Brody6mo ago
awesome
Chioma
Chioma6mo ago
thanks brody
Brody
Brody6mo ago
no problem!
Chioma
Chioma6mo ago
what do those files do?
Brody
Brody6mo ago
they download and run caddy to serve your frontend
Chioma
Chioma6mo ago
got it
Brody
Brody6mo ago
there's a section in this repos readme about caddy
Chioma
Chioma6mo ago
i checked it out! appreciate it Hey Brody! Is this thread still open? I have a follow up question if that's alright
Brody
Brody6mo ago
of course what is the question
Chioma
Chioma6mo ago
Thanks Brody! It was about something you changed on the last project I deployed, and I am just trying to understand to implement again! https://github.com/ChiomaGrace/MyPortfolio/blob/master/frontend/src/app/shared.service.ts
GitHub
MyPortfolio/frontend/src/app/shared.service.ts at master · ChiomaGr...
Contribute to ChiomaGrace/MyPortfolio development by creating an account on GitHub.
Chioma
Chioma6mo ago
Import.meta.env - this is a way to get the front end to talk to the backend routes right?
Brody
Brody6mo ago
that's just how you access environment variables in the code
Chioma
Chioma6mo ago
okay gotcha. would you mind if I ask why the way I am currently trying to do it isn't working, or do you answer questions more to do with deployment?
Brody
Brody6mo ago
very likely because you aren't using this in your new project https://www.npmjs.com/package/@ngx-env/builder that's what I used when I made changes to your other project makes using environment variables in your angular code much easier and straightforward than the native way angular would have you do it
Chioma
Chioma6mo ago
okay! thanks brody!! looking into it now Brody I am getting the console log from my backend! On my index page. But the route that submits my form is still not working, and I don't see the console logs from there either. Any suggestions on where I should look to debug?
Brody
Brody6mo ago
can you show some example screenshots of what you mean? not too sure i understand whats going on
Chioma
Chioma6mo ago
sure thing! Here is my server.js that connects to my routes.js: My routes.js: Only the get method seems to be working right now The method I am trying to see run through my routes How i implemented the environment variable:
Brody
Brody6mo ago
you went back to serving your frontend from the backend again
Chioma
Chioma6mo ago
i referenced our last to chat to make sure i understood everything. i set it up incorrectly still?
Brody
Brody6mo ago
yes you have, here you are sending the the frontend from the backend
Chioma
Chioma6mo ago
ah okay. i did notice on my other app i didn't have that, but i couldn't see how the frontend was being served without it
Brody
Brody6mo ago
locally the frontend is ran with its dev server, on railway the frontend is ran with caddy, i think we've talked about this a few times?
Chioma
Chioma6mo ago
loads. and i apologize. i am even trying to make documentation to make sure i understand but locally and in development just seems so different. i know locally i would have
ng build --watch
ng build --watch
and
nodemon server.js
nodemon server.js
and run the project on localhost 8000 and this would show the front end in development i an running
ng build --watch --configuration development
ng build --watch --configuration development
and
railway run npm run start
railway run npm run start
in another terminal but i do not see my front end unless i have that get statement. this is different than local and this is where i get super confused
Brody
Brody6mo ago
maybe reference our previous threads? i think youve asked this exact question and i gave you a breakdown
Chioma
Chioma6mo ago
ive referenced it, and i've made documentation even, but i understand if you cant break it down more than u have. https://docs.google.com/document/d/1qwldEEzUCqNmgkG7-mVpK_R7ZMYBJO3ZqZKUPUm-_lM/edit i'll look at it again
Brody
Brody6mo ago
locally during development: - two vscode windows open. - run ng serve to start the frontend. https://angular.io/cli/serve - run nodemon server.js to start the backend. these commands start two completely separate dev servers.
Chioma
Chioma6mo ago
correct. im w you there this time i deployed first, because i had such a hard time grasping everything, and i wanted to continually working locally after deploying
Brody
Brody6mo ago
nothing i have ever said prevents you from working locally at any point
Chioma
Chioma6mo ago
correct, but there was a lot of setup that altered that i didn't initially have
Brody
Brody6mo ago
this is true, but it was only initial setup
Chioma
Chioma6mo ago
yes! so i was trying to do the inital setup as we did before everything is what im trying to say
Brody
Brody6mo ago
yes but instead you went back to serving your frontend from the backend, exactly what we where getting away from with all that setup we have done in the past
Chioma
Chioma6mo ago
okay. so if i remove that get function is the setup correct?
Brody
Brody6mo ago
i mean its a step in the right direction, but i would need to know the rest of your setup in order to answer that question
Chioma
Chioma6mo ago
i mirrored the other thread you helped me on
Chioma
Chioma6mo ago
GitHub
GitHub - ChiomaGrace/AngularApp
Contribute to ChiomaGrace/AngularApp development by creating an account on GitHub.
Brody
Brody6mo ago
quick side question, you are not the first ive seen to have a pokemon related frontend and backend project, are you following some kind of tutorial?
Chioma
Chioma6mo ago
nope. i am trying to just do a CRUD app based off our last chat to make sure i get everything. just picked pokemon as the subject matter at random
Brody
Brody6mo ago
oh interesting can i see a screenshot of your railway project?
Chioma
Chioma6mo ago
Brody
Brody6mo ago
your repo needs a .gitignore file, use this https://www.toptal.com/developers/gitignore/api/node,angular in the root of the repo you have committed your .env file to the repo, please delete it. also delete the node_modules folder. https://github.com/ChiomaGrace/AngularApp/blob/main/frontend/src/app/shared.service.ts#L14 the import should be import.meta.env["NG_APP_BACKEND_URL"] https://github.com/ChiomaGrace/AngularApp/blob/main/frontend/.env.local#L1 this variable should be named NG_APP_BACKEND_URL the variable in the service variables on railway should also be named that have you integrated https://www.npmjs.com/package/@ngx-env/builder yet?
Chioma
Chioma6mo ago
i did integreate the biulder yes, but i did name my variables differently.... i just named it backend_url. so the "ng app" part of the name is crucial?
Brody
Brody6mo ago
yes it is, from the docs, otherwise you will get undefined we are going to use the default NG_APP_ prefix https://github.com/ChiomaGrace/AngularApp/blob/main/frontend/.env.local#L1 the value for that variable should be http://127.0.0.1:8000 since your backend will run locally on port 8000
Chioma
Chioma6mo ago
oh okay. i will adjust. is this the same with "FRONTEND ORIGIN"? That is what I used on the app that works But on the one pokemon one i named it frontend url
Brody
Brody6mo ago
the backend does not need any variable prefixes, thats only a frontend thing
Chioma
Chioma6mo ago
got it adjusting now
Brody
Brody6mo ago
though you have the incorrect variable in the service variables as opposed to whats in your code https://github.com/ChiomaGrace/AngularApp/blob/main/backend/server.js#L16 these little things can make or break entire site functionality
Chioma
Chioma6mo ago
the variable in my service is this. i just adjusted because of what we just discussed this is incorrect?
Brody
Brody6mo ago
yes it is
Chioma
Chioma6mo ago
oh shoot. then i am even more confused i think. isn't this how we setup the service in my previous app? https://github.com/ChiomaGrace/MyPortfolio/blob/master/frontend/src/app/shared.service.ts
Brody
Brody6mo ago
here is your screenshot showing a variable in use in your code with the NG_APP_ prefix you will not be able to access a variable on the frontend if it does not have NG_APP_ prefixed
Chioma
Chioma6mo ago
yes! that's what you just explained. okay sorry i thought you were saying this is incorrect. this is what i just changed in railway and in the code. i added the rpefix
Brody
Brody6mo ago
have you made all the suggestions here? im not seeing any changes on the repo?
Chioma
Chioma6mo ago
not yet. when i deleted the node module folder it created issues so i was going to put it back first
Brody
Brody6mo ago
you delete the node_modules folder from the repo, not locally
Chioma
Chioma6mo ago
this makes sense ha okay i deployed again w the changes Have some errors on Railway
Brody
Brody6mo ago
you have not yet removed the node_modules folder
Chioma
Chioma6mo ago
looks like i didnt commit the change. theyre gone now
Brody
Brody6mo ago
okay let me know if the build still fails
Chioma
Chioma6mo ago
okay it didnt fail! it is up and working https://angular-app-frontend-production.up.railway.app/ but locally i get this when i remove the get function
Brody
Brody6mo ago
thats normal, you need to open the url of the frontend dev server to access the frontend, not the backends url
Chioma
Chioma6mo ago
as in run on localhost 4200?
Brody
Brody6mo ago
i think thats what ng will run the dev server on you have ng serve as the start script on your frontend so you only need to run npm run start locally in vscode opened to the frontend folder
Chioma
Chioma6mo ago
npm run start wasnt working so i was using
ng build --watch --configuration development
ng build --watch --configuration development
Brody
Brody6mo ago
when you run into issues, please tell me, dont just jump to something else ng build does not start the development server, without running ng serve you will have no way of opening the frontend locally
Chioma
Chioma6mo ago
sorry brody. i'll tell you now for sure i have ran npm run start in one terminal, and it is running on localhost 4200! i tried to submit the form as a test but i dont think it's going to the route
Brody
Brody6mo ago
what route does it request? via the 3 dot menu of the dev tools, pop it out into a seprate window for ease of use
Chioma
Chioma6mo ago
it should go to the submitPokemon route
Brody
Brody6mo ago
right, but what does it actually go to when you click the submit button pop out the dev tools please, then go to the network tab
Chioma
Chioma6mo ago
Brody
Brody6mo ago
why is everything so big?
Chioma
Chioma6mo ago
you requested for me to make it its own window no?
Brody
Brody6mo ago
yeah but youre all zoomed in, zoom out lol
Chioma
Chioma6mo ago
oh it's not zoomed in
Brody
Brody6mo ago
haha yes it is
Chioma
Chioma6mo ago
i just opened it in a new window as requested. i didn't zoom in on anything
Brody
Brody6mo ago
its zoomed in, but nevermind that. show me the failed request please
Chioma
Chioma6mo ago
how do i do that? what do u want to see on the network tab?
Brody
Brody6mo ago
the form submission api call
Chioma
Chioma6mo ago
nothing displays in the fetch/xhr tab
Brody
Brody6mo ago
then your frontend isnt even calling the api
Chioma
Chioma6mo ago
this is what i was trying to say here oh and i see the terminal is saying this
Brody
Brody6mo ago
im not an agular dev so im no help there
Chioma
Chioma6mo ago
fair enough. but it's this return statement that isn't working here: do you by chance know why? i see in my other app i have this file, but i didn't add this. is this something you imported? this:
Brody
Brody6mo ago
that would be something ngx-env added but you have to focus on why your frontend is not making an api call
Chioma
Chioma6mo ago
the return statement right? that's the only thing the function isn't running. the component with the form goes to the service as expected. then the service runs correctly until the return statement
Brody
Brody6mo ago
the import.meta.env part itself correct, i dont know about anything around that
Chioma
Chioma6mo ago
got it going to the back end now! just getting a 500 error though
Brody
Brody6mo ago
what are the logs saying on the backend? 500 is usually inductive of a code / config issue
Chioma
Chioma6mo ago
Brody
Brody6mo ago
yep just a code issue, looks like you got a little debugging to do
Want results from more Discord servers?
Add your server
More Posts
upgrade to pro issuejust upgraded to pro plan, but getting this after i transferd my projectWriting files to a disk increases RAM usageI have a simple program that lets the user send the video. It downloads it and saves to the disk. NoRailway created a new team while I wanted to upgrade my other teamHi there, recently I tried to upgrade my team from the hobby plan to the pro plan to get access to tError: Cannot find module './pnpm.cjs' when trying to build an Nx monorepo appI might just be off the beaten track here with pnpm, as this looks like a build system error rather DockerFile fails to install packages with yarn install and doesn't generate node_modulesThis is my DockerFile ```# Build stage FROM node:18 as builder WORKDIR /app COPY package.json . COPYv2 Migration: N8N - Application failed to respondAfter migrating to v2, I can no longer access my N8N installation. Migration seems to have been compHow to fix 'Application failed to respond' error and add Python (flask) to Nextjs app on Railway?**Context/What I want to do:** I have an app that uses nextjs and flask. I have the following folderConcern: Discrepancy in Billing - Excess Amount Reflecting Against UsageDear Railway Team, I hope this message finds you well. I am writing to you regarding a recent billsudden spike in egress usageHey, since I migrated my DB to v2, my egress has shot up. I want to know if these are related and alRailway occasionally fails to detect open portsI've recently created the `SurrealDB` template for Railway, and upon further experimentation I've fo