Error - Cant find folder or Cant find package.json

I cannot get the correct Root Directory setting to Build & Deploy my sample Front End. The pacgake.json file is in sample/client. The app.js and index.js files are in sample/client/src

I have tried
./client
client/
sample/client
client/scr

I am a newbie, any help would be greatly appreciated

Hi there,

sample/client should work for the root directory. What errors were you seeing when you tried this?

Regards,

Keith
Render Support, UTC+10 :australia:

Thanks for the reply.

It did find my package.json. Now I am getting the error "Cannot find module ‘/opt/render/project/src/client/app.js’. My package.json is in the client folder, but my app.js is in the client/src folder. I ran ‘npm create-react-app’, the folder structure was created.

How can I get Render to find both package.json and app.js when they are in different folders?

here is a link to my sample e-comm web app on git: https://github.com/easoftwareGit/e_commerce_2

Hi there,

when i face that error i just simply change my build command in render like below :-

Hoping this will also fix your problem

Thanks for the reply. Updating the Build Command got the deploy farther before crashing, but I am still getting an error. The error is now:

Error: Cannot find module ‘/opt/render/project/src/client/app.js’

I know the app.js file not in /src/client, because it is in /client/src/

Hi there,

You should deploy your client as a static site, not as a web service. The issue here is your src/App.js is part of your React app (not you don’t have an app.js anywhere in your app). It is not running a web server like Express to serve your built React app. You could use react-scripts start (or just npm start) but it is not recommended to do this in a production environment.

You can see an example of a static site React app here: https://render.com/docs/deploy-create-react-app. In your specific case, I would use npm run build instead of yarn build. The publish directory would remain as build. This removes the need to run Express.

To use a web service instead of a static site, you must create a script to serve your built React app. Create a index.js in your client folder, which has something like this:

const express = require('express');const app = express();app.use(express.static('build'));const path = require('path');app.get('*', (req, res) => { res.sendFile(path.resolve(__dirname, 'build', 'index.html'))});const port = process.env.PORT || 5000;app.listen(port, () => { console.log(`Server started on port: ${port}`);});

Your start command would then be node index.js.

To answer your issue directly, the problem is your start command node app.js which means it’s looking for app.js in the root dir of your service. All use code is located under /opt/render/project/src. This combined with your client root dir setting makes the full path /opt/render/project/src/client/app.js. Which doesn’t exist in your application.

Regards,

Keith
Render Support, UTC+10 :australia:

Winner Winner Chicken Dinner! Thanks to both of you for all your help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.