MERN Deploy Heroku Fail

Hey guys…
Issues attempting to deploy to heroku.

{
  "name": "server",
  "version": "1.0.0",
  "engines": {
    "node": "14.17.6"
  },
  "description": "",
  "main": "index.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "keywords": [],
  "author": "Aryse <medictansy@gmail.com>",
  "license": "MIT",
  "dependencies": {
    "concurrently": "^7.1.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.0",
    "express": "^4.17.3",
    "mongoose": "^6.2.10",
    "morgan": "^1.10.0"
  }
}

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"));
  });
}
-----> Build
       Running heroku-postbuild
       
       > server@1.0.0 heroku-postbuild
       > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
       
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /tmp/build_5125288f/client/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_5125288f/client/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.5oVm8/_logs/2022-04-21T20_05_11_084Z-debug-0.log
-----> Build failed

When I run Dev:

[1] npm ERR! code ENOENT
[1] npm ERR! syscall open
[1] npm ERR! path /Users/arysetansy/Desktop/All Projects/List Of Projects/MERN/Expense-Tracker/server/client/package.json
[1] npm ERR! errno -2
[1] npm ERR! enoent ENOENT: no such file or directory, open '/Users/arysetansy/Desktop/All Projects/List Of Projects/MERN/Expense-Tracker/server/client/package.json'
[1] npm ERR! enoent This is related to npm not being able to find a file.
[1] npm ERR! enoent 
[1] 
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR!     /Users/arysetansy/.npm/_logs/2022-04-21T20_08_41_824Z-debug-0.log
[1] npm run client exited with code 254
[0] Spinning
[0] Connected
[0] GET / 404 8.650 ms - 139

Thanks in advance

I believe its looking for Client inside Server… Anything Helps, guys.
Thanks

I think it should be npm --prefix folderPath commandToRun

But I might forgo the --prefix flag and just cd into the client directory and run the commands. I think there are some oddities with that flag.

cd ./client && npm i && npm run build

Also, in your app.get I would assume it should be * and not #.

Thanks! I Attempted with the Command you suggested before and it also did not work. I Ended up deploying… but I had to deploy the backend (Heroku) and then the frontend (Netlify)…
Its up and running, but ultimately doesnt address the fact that I was running into those errors when attempting to deploy them together… =(

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