Hi!

I have a problem trying to deploy my app. I recognize is quite tricky but it's the best solution I found to have the structure I need. My app it's a Vite/ReactJS app and it runs perfectly, but I need to create a blog so I decide to create a solution with Astro inside my Vite/ReactJS app. So my structure looks like a tipical ReactJS app but I created a /blog folder with a Astro project and I modified my build script and looks like this "build": "vite build && cd blog && npm run build" vite build works fine but I have a problem with Astro
24.63 sh: 1: astro: not found
24.66 error Command failed with exit code 127.
24.66 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
24.63 sh: 1: astro: not found
24.66 error Command failed with exit code 127.
24.66 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Looks like astro build it's not working. I try to add engine: 18 on my package.json but it doesn't works. Thanks for your help and patience
Solution:
yes but thats not a good idea in my opinion, can we instead have your react app on domain.com, and your blog on blog.domain.com?
Jump to solution
81 Replies
Percy
Percy11mo ago
Project ID: 863d09e4-f366-4c2c-90bc-5991b840e2a0
Brody
Brody11mo ago
could you share your repo, that would give us the best possible overview of what you are trying to do
Oscar Bustos
Oscar Bustos11mo ago
863d09e4-f366-4c2c-90bc-5991b840e2a0 It's private but If you want I can share with your github user
Brody
Brody11mo ago
yes please, brody192
Oscar Bustos
Oscar Bustos11mo ago
Ok I just added you
Brody
Brody11mo ago
any specific branch i should be looking at?
Oscar Bustos
Oscar Bustos11mo ago
main directly
Brody
Brody11mo ago
so you just want to deploy the app within /blog and dont care about anything in the root?
Oscar Bustos
Oscar Bustos11mo ago
yeah my idea it's to deploy the asto into the dist folder like an static project so I think this approach it was the best to achive it making both builds at the same time
Brody
Brody11mo ago
does anything in /blog depend on anything outside of /blog?
Oscar Bustos
Oscar Bustos11mo ago
nope It's independent
Brody
Brody11mo ago
perfect, so first things first, you will need to configure your blog app to use the node adapter
Oscar Bustos
Oscar Bustos11mo ago
makes sense ok
Brody
Brody11mo ago
example https://github.com/brody192/astrowind-template/blob/main/astro.config.mjs#L34-L40 let me know when done! there is steps after this, but one thing at a time
Oscar Bustos
Oscar Bustos11mo ago
ok, I just pushed the node adapter
Brody
Brody11mo ago
that was fast, ill take a look missed the server object
Oscar Bustos
Oscar Bustos11mo ago
server: {
host: '0.0.0.0'
},
server: {
host: '0.0.0.0'
},
ok added
Brody
Brody11mo ago
okay in the blog's package.json set the start script to node dist/server/entry.mjs and also remove any build or start commands you may have set in your services settings
Oscar Bustos
Oscar Bustos11mo ago
👍🏻 OK the scripts in the blog looks like this
"scripts": {
"dev": "astro dev",
"start": "node dist/server/entry.mjs",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"scripts": {
"dev": "astro dev",
"start": "node dist/server/entry.mjs",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
Brody
Brody11mo ago
looks good, now just set the root directory in the service settings to /blog
Oscar Bustos
Oscar Bustos11mo ago
ok its redeploying it fails
Brody
Brody11mo ago
no worries, lets work through it, can you send me the build logs please https://bookmarklets.up.railway.app/log-downloader/
Oscar Bustos
Oscar Bustos11mo ago
sorry the tool doesn't works but heres the log
Brody
Brody11mo ago
what browser are you using?
Oscar Bustos
Oscar Bustos11mo ago
chrome ok now works
Brody
Brody11mo ago
always has
Oscar Bustos
Oscar Bustos11mo ago
it was my fault sorry
Brody
Brody11mo ago
can you run npm run build locally?
Oscar Bustos
Oscar Bustos11mo ago
ok on root right? i have an error
Cannot find package '@astrojs/internal-helpers' imported from /Users/elchiconube/Projects/personal/memos.land/frontend/dist/blog/dist/server/manifest_YLt2YtOP.mjs
Stack trace:
at new NodeError (node:internal/errors:405:5)
at moduleResolve (node:internal/modules/esm/resolve:939:20)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at link (node:internal/modules/esm/module_job:76:36)
Cannot find package '@astrojs/internal-helpers' imported from /Users/elchiconube/Projects/personal/memos.land/frontend/dist/blog/dist/server/manifest_YLt2YtOP.mjs
Stack trace:
at new NodeError (node:internal/errors:405:5)
at moduleResolve (node:internal/modules/esm/resolve:939:20)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at link (node:internal/modules/esm/module_job:76:36)
Brody
Brody11mo ago
in the blog folder run npm run build
Oscar Bustos
Oscar Bustos11mo ago
ah ok same issue
Cannot find package '@astrojs/internal-helpers'
Cannot find package '@astrojs/internal-helpers'
Brody
Brody11mo ago
okay please get your app building locally
Oscar Bustos
Oscar Bustos11mo ago
i'm adding this package mmm looks like i need to install multiple packages but not sure if do it on blog or root directory
Brody
Brody11mo ago
blog is isolated from the rest as youve said
Oscar Bustos
Oscar Bustos11mo ago
oki ok looks like locally runs fine I just pushed it fails again
Brody
Brody11mo ago
in the blog folder, can you run npm run build locally?
Oscar Bustos
Oscar Bustos11mo ago
yes, I just pushed again with the yarn.lock file
Brody
Brody11mo ago
locally do you use yarn or npm?
Oscar Bustos
Oscar Bustos11mo ago
I used to use yarn
Brody
Brody11mo ago
what do you use now?
Oscar Bustos
Oscar Bustos11mo ago
If i try yarn build in the root I see this error
"default" is not exported by "ckeditor5/build/ckeditor.js", imported by "src/components/MemoryEditor.jsx
"default" is not exported by "ckeditor5/build/ckeditor.js", imported by "src/components/MemoryEditor.jsx
I prefer yarn
Brody
Brody11mo ago
im not sure why you are trying to do stuff in the root? this thread is about running the blog on railway, right?
Oscar Bustos
Oscar Bustos11mo ago
yes sorry
Brody
Brody11mo ago
can you build the blog locally with yarn?
Oscar Bustos
Oscar Bustos11mo ago
yes works fine in my local
Brody
Brody11mo ago
what command do you run locally yo build blog? and what folder are in you when you do that?
Oscar Bustos
Oscar Bustos11mo ago
npm run build
Brody
Brody11mo ago
???
Oscar Bustos
Oscar Bustos11mo ago
maybe I missunderstand something sorry
Brody
Brody11mo ago
what version of node are you using locally
Oscar Bustos
Oscar Bustos11mo ago
v18.18.0 i saw this in the build log
#12 4.663 Cannot find package 'cookie' imported from /dist/blog/dist/server/manifest_YyjHGfxx.mjs
#12 4.663 Cannot find package 'cookie' imported from /dist/blog/dist/server/manifest_YyjHGfxx.mjs
I added in my local and the build works fine but It doesn't work on server 😦
Brody
Brody11mo ago
whats your root directory set to on your railway service?
Oscar Bustos
Oscar Bustos11mo ago
No description
Brody
Brody11mo ago
unfortunately i dont know why you get that error, but it is a code issue, so please try your best to resolve it
Oscar Bustos
Oscar Bustos11mo ago
mmm looks like it´s something related with the adapter if I set it to static it deploys fine, but it crash because the adapter node its for output server so I think its not a code issue it works fine in my local
Brody
Brody11mo ago
for railway, it needs to use a node adapter this isnt an issue with railway, i know that much
Oscar Bustos
Oscar Bustos11mo ago
maybe its not compatible also it's so strange i need to add packages manually that I dont use in my code
Brody
Brody11mo ago
i have an astro template and it works just fine, this isnt an issue with railway
Oscar Bustos
Oscar Bustos11mo ago
looks like astro in server output needs something that it´s not compatible with the build process mmm if I put your template into the blog folder should be fine?
Brody
Brody11mo ago
some kinda of config / code issue on your part yeah theoretically
Oscar Bustos
Oscar Bustos11mo ago
I'll try
Brody
Brody11mo ago
i just deployed the template, no issues https://astrowind-site-production-b7e0.up.railway.app/
Oscar Bustos
Oscar Bustos11mo ago
mmm yes but my configuration its something more complex. I have my reactJs and the astro blog
Brody
Brody11mo ago
you said blog is completely separate and doesn’t rely on anything outside of the blog folder you cant copy in 1/4 of the astrowind project and expect it to build
Oscar Bustos
Oscar Bustos11mo ago
sorry maybe I didn't explain what I need. 1. Build my Vite/React app 2.Build my Astro blog and put it into the Vite/React /dist/blog folder That's why my first idea was change my build script into the React app into this
"build": "cd blog && astro build && cd .. && vite build",
"build": "cd blog && astro build && cd .. && vite build",
Is it possible?
Solution
Brody
Brody11mo ago
yes but thats not a good idea in my opinion, can we instead have your react app on domain.com, and your blog on blog.domain.com?
Oscar Bustos
Oscar Bustos11mo ago
Well I'm planning to have a great url domain.com/blog/first-blog domain.com/blog/es/primer-blog domain.com/blog/en/primer-blog
Brody
Brody11mo ago
blog.domain.com/first-blog
blog.domain.com/es/primer-blog
blog.domain.com/en/primer-blog
blog.domain.com/first-blog
blog.domain.com/es/primer-blog
blog.domain.com/en/primer-blog
Oscar Bustos
Oscar Bustos11mo ago
I get it ok
Brody
Brody11mo ago
thats the better solution in my opinion, its how railway does it too
Oscar Bustos
Oscar Bustos11mo ago
but why it's not a good idea my first approach?
Brody
Brody11mo ago
you are building two completely separate apps and then combining them, im sure i could work out a decent way to do that, but blog.domain.com is far better and more appropriate
Oscar Bustos
Oscar Bustos11mo ago
mmm ok. I'll think about it. Thanks for your time @Brody . I really appreciate it ❤️
Brody
Brody11mo ago
for the record, in my experience, it is never a good idea to be cd'ing around like this, and when cd is used like this, it usually means you are doing something wrong.
Oscar Bustos
Oscar Bustos11mo ago
My other idea was to move everything to NextJS but it's to hard to move everything to NextJS just because I need a blog in my project mildpanic agree. It was the first time I used this kind of solution
Brody
Brody11mo ago
so yeah, going forward you want an isolated mono repo. in the repo you want two folders /blog and /mysite (or whatever you wanna name it) then in railway you will have two services, each set with the appropriate root dir and with the applicable domain added astro still needs to build with the node adapter though, so you still need to sort those build errors out
Oscar Bustos
Oscar Bustos11mo ago
Ok will try your solution creating a subdomain. Thanks
Want results from more Discord servers?
Add your server