I have a next error: Error: ENOENT: no such file or directory, stat '/opt/render/project/src/client/build/index.html

HI, could somebody help me?
I have a next error: Error: ENOENT: no such file or directory, stat '/opt/render/project/src/client/build/index.html

My code here:
if (process.env.NODE_ENV === “production”) {
app.use("/", express.static(path.join(__dirname, “client”, “build”)));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, “client”, “build”, “index.html”));
});
}

Serever starts on port 10000… (response err 404)
Thanks in advance :slight_smile:

If you’re not using our free tier, you can use the shell tab to look at the filesystem of what you’ve deployed to see if /opt/render/project/src/client/build/index.html actually exists on the filesystem. The error suggests it’s not there - is it the result of a build process?

John B

I use a free plan.
My build process is ok:
Apr 19 01:48:34 PM ==> Generating container image from build. This may take a few minutes…
Apr 19 01:52:46 PM ==> Uploading build…
Apr 19 01:53:38 PM ==> Build successful :tada:
Apr 19 01:53:38 PM ==> Deploying…
Apr 19 01:54:15 PM ==> Starting service with ‘yarn start’
Apr 19 01:54:18 PM yarn run v1.22.5
Apr 19 01:54:19 PM $ cross-env NODE_ENV=production node app.js
Apr 19 01:54:21 PM WARNING: NODE_ENV value of ‘production’ did not match any deployment config file names.
Apr 19 01:54:21 PM WARNING: See Strict Mode · node-config/node-config Wiki · GitHub
Apr 19 01:54:26 PM Server has been started on port 10000…

1 Like

Does the path client/build exist within your repo? If not, is there a script that needs to be run as part of the build to generate what you’re expecting there?

John B

1 Like

There are my scripts:
“scripts”: {
“start”: “cross-env NODE_ENV=production node app.js”,
“server”: “nodemon app.js”,
“client”: “yarn --cwd client run start”,
“client:install”: “yarn --cwd client add”,
“client:build”: “yarn --cwd client run build”,
“dev”: “cross-env NODE_ENV=development concurrently “yarn server” “yarn client””,
“heroku-postbuild”: “NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client”
},
I think, “heroku-postbuild” is not compatible and I have to use yarn.

ok, so if you’re just running yarn it’s my understanding that the default behaviour there is to do a yarn install - it could be that you need to add additional commands… eg yarn && yarn ..... etc

John B

Here are my scripts now:
“scripts”: {
“start”: “cross-env NODE_ENV=production node app.js && yarn client:install && yarn client:build”,
“server”: “nodemon app.js”,
“client”: “yarn --cwd client run start”,
“client:install”: “yarn --cwd client add react-scripts --save”,
“client:build”: “yarn --cwd client run build”,
“dev”: “cross-env NODE_ENV=development concurrently “yarn server” “yarn client””
}

But I stiil have a problem: when I use “start”: “cross-env NODE_ENV=production node app.js && yarn client:install && yarn client:build” server ran only node app.js.
When I use “start”: “cross-env NODE_ENV=production node app.js & yarn client:install & yarn client:build” server ran node app.js and installed packages for client, but server ran client build at the same time, when client packages were installed, cliend build caused error.
The “start” script was called endlessly in a circle. Can you find any mistakes in this script?

When I tried to run right variant of the script “start”: “cross-env NODE_ENV=production node app.js & yarn client:install && yarn client:build” the server ran node app.js and installed packages for client, then the server ran build and the error happened in this process “The build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process.” I don’t know the reason of this error.

Apr 21 01:59:23 AM $ yarn --cwd client run build
Apr 21 01:59:25 AM $ react-scripts build
Apr 21 01:59:47 AM Creating an optimized production build…
Apr 21 02:00:40 AM The build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process.
Apr 21 02:00:41 AM error Command failed with exit code 1.
Apr 21 02:00:41 AM info Visit yarn run | Yarn for documentation about this command.

May be I need a server with more memory?

I took your repo and deployed it myself to see what was going on here, if you set your buildCommand to yarn client:install && yarn client:build and your startCommand to node app.js then your service deploys successfully.

John B

1 Like

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