R
Railwayā€¢9mo ago
cern7

npm install not being able to find a file

ProjectID: ff2c534b-823e-40f6-a709-db146cfd1f3d trying to deploy UI part of my app, dockerfile is giving me hard time, I followed all articles about how to create Dockerfile for react app, but getting same error, => package.json cannot be found. Folder structure : attached Dockerfile instructions: FROM node:19-alpine Create a directory inside the container to copy the files WORKDIR /app Copy the package.json and package-lock.json first to leverage Docker cache if dependencies haven't changed COPY package*.json ./ Install dependencies RUN npm install Copy the rest of the app files COPY . . Expose the required port EXPOSE 5173 Start the application CMD ["npm", "run", "dev"] What am I doing wrong ?
No description
No description
Solution:
you are also missing your vite config file from the repo, without that react wont be integrated into the build
Jump to solution
44 Replies
Percy
Percyā€¢9mo ago
Project ID: N/A
cern7
cern7ā€¢9mo ago
did add .dockerignore, on the same level, didn't help
No description
No description
Floris
Florisā€¢9mo ago
your logs are saying it's trying to look for the package.json in /app however it seems like you have it in root ./
Brody
Brodyā€¢9mo ago
Morpheus, the workdir is set to /app in the dockerfile @cern7 is this create-react-app?
cern7
cern7ā€¢9mo ago
no, it is my react application I developed
Brody
Brodyā€¢9mo ago
does it use create-react-app
cern7
cern7ā€¢9mo ago
no, I used npm create vite@latest my-app --template react
Brody
Brodyā€¢9mo ago
ah cool vite react app delete your dockerfile https://github.com/brody192/vite-react-template copy the nixpacks.toml and Caddyfile from this repo into yours make sure you have not set any build or start commands in your services settings
cern7
cern7ā€¢9mo ago
should I add some other settings to the service or any Variables ?
Brody
Brodyā€¢9mo ago
dont think it would be needed, those should just be drag and drop, but if theres any issues ill be here!
cern7
cern7ā€¢9mo ago
No description
cern7
cern7ā€¢9mo ago
the vite (client) is in UI/notife-me-app-ui/
cern7
cern7ā€¢9mo ago
@Brody
No description
Brody
Brodyā€¢9mo ago
in the service settings set the root directory to /UI/notife-me-app-ui no need to ping, I'm here
cern7
cern7ā€¢9mo ago
sorry
Brody
Brodyā€¢9mo ago
no worries
cern7
cern7ā€¢9mo ago
if path doesn't exist, redirect it to 'index.html' for client side routing try_files {path} /index.html
cern7
cern7ā€¢9mo ago
No description
Brody
Brodyā€¢9mo ago
yes, you have a single page react app, that is necessary do you think you could share your repo?
cern7
cern7ā€¢9mo ago
GitHub
GitHub - cern7/notifyMe
Contribute to cern7/notifyMe development by creating an account on GitHub.
Brody
Brodyā€¢9mo ago
looking
cern7
cern7ā€¢9mo ago
thx
Brody
Brodyā€¢9mo ago
can you show me this same screenshot, but of your local folder instead of github?
cern7
cern7ā€¢9mo ago
No description
Brody
Brodyā€¢9mo ago
you have an index.html there, but not in the repo?
cern7
cern7ā€¢9mo ago
you re right should have pay attention šŸ˜„
Brody
Brodyā€¢9mo ago
do you know why it isnt in the repo?
cern7
cern7ā€¢9mo ago
I didn't add it šŸ˜¦ It is active now will continue testing, the back end and db thanks a lot
Brody
Brodyā€¢9mo ago
the build went through and the site is live?
cern7
cern7ā€¢9mo ago
No description
Solution
Brody
Brodyā€¢9mo ago
you are also missing your vite config file from the repo, without that react wont be integrated into the build
cern7
cern7ā€¢9mo ago
y right home page is loaded
Brody
Brodyā€¢9mo ago
didnt even know you could run a vite build without its config file lol
cern7
cern7ā€¢9mo ago
thanks a lot
Brody
Brodyā€¢9mo ago
no problem!
cern7
cern7ā€¢9mo ago
how can I add variable place holder to caddyfile ?
No description
cern7
cern7ā€¢9mo ago
No description
cern7
cern7ā€¢9mo ago
to use it liket this
cern7
cern7ā€¢9mo ago
now I have:
No description
Brody
Brodyā€¢9mo ago
to use environment variables in vite they need to be prefixed with VITE_ otherwise vite won't build the variable into your app for security reasons. in railway set a variable VITE_BACKEND_API_URL to https://${{notifyMe.RAILWAY_PUBLIC_DOMAIN}} in your code the BASE_API const should be import.meta.env.VITE_BACKEND_API_URL + "/api/auth/login" this is all great for when on railway, but we don't necessarily want to call the backend that's running on railway when developing locally, for that you can add a .env.local to your project with the same variable, but the value being the address of the locally running backend api VITE_BACKEND_API_URL=http://127.0.0.1:8000 that way, when developing locally, the local backend url is used automatically, giving you a seamless transition from developing locally to running on railway
cern7
cern7ā€¢9mo ago
Hey Brody thanks It helped is there any setting where I can update this Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://notifyme.railway.internal/api/auth/register. (Reason: CORS request did not succeed).
cern7
cern7ā€¢9mo ago
No description
Brody
Brodyā€¢9mo ago
that would have to be done in the code for your backend and thats done in java, unfortunately i have zero experience with java
cern7
cern7ā€¢9mo ago
thank you Brody