1

I have two main folders for my project: server and client. Heroku only seems to care about the server/package.json. Deployment is going fine until it returns an error when the process runs the "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" command from package.json.

Here's the error message from the console:

-----> Build
remote:        Running heroku-postbuild
remote:        
remote:        > server@1.0.0 heroku-postbuild
remote:        > npm install --prefix client && npm run build --prefix client
remote:        
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_25b1f86c/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_25b1f86c/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent 
remote: 
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.3i4hV/_logs/2022-08-05T15_34_56_961Z-debug-0.log
remote: 
remote: -----> Build failed

Here's server/package.json:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": "16.16.0",
    "npm": "8.11.0"
  },
  "scripts": {
    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "npm run 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"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.20.0",
    "concurrently": "^7.3.0",
    "cookie-session": "^2.0.0",
    "express": "^4.18.1",
    "mongoose": "^6.5.0",
    "nodemon": "^2.0.19",
    "passport": "^0.5.3",
    "passport-google-oauth20": "^2.0.0",
    "stripe": "^10.0.0"
  }
}

Here's client/package.json:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^0.27.2",
    "http-proxy-middleware": "^2.0.6",
    "materialize-css": "^1.0.0-rc.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-redux": "^8.0.2",
    "react-router-dom": "^5.3.3",
    "react-scripts": "5.0.1",
    "react-stripe-checkout": "^2.6.3",
    "redux": "^4.2.0",
    "redux-thunk": "^2.4.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I tried removing parts of "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" to shorten it into "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false" in other deployments and it worked. It seems "npm install --prefix client && npm run build --prefix client" is the part not working in the heroku-postbuild script.

Would you have any idea how to fix this? Thanks!

thib
  • 68
  • 1
  • 8
  • 1
    This has nothing to do with Git (see [the top of my answer here](https://stackoverflow.com/a/73252857/1256452) for more about that). What's going on is that `client/package.json` is missing. Whether it's *really* supposed to exist, I have no idea, but something in your code says that it is supposed to exist, and it doesn't. – torek Aug 05 '22 at 16:46
  • Thank you @torek for your help! I have, indeed, a client/package.json file, which exists. I edited the original post to include it. In that architecture, the `client` folder is within the `server` folder. Reading your answer, I still couldn't make it work. Would you have another option to explore? – thib Aug 05 '22 at 17:38
  • 1
    Huh, that part looks OK - at this point you need an npm and/or node.js expert. – torek Aug 05 '22 at 22:16
  • Ok, thanks, good to know! I'll keep digging. Still haven't fixed it for now. – thib Aug 06 '22 at 06:15

1 Answers1

1

OK, found it. My course TA helped me figure it out. The solution below worked.

In my Github repo called server, the client directory was completely missing, so, the Heroku server was likely having the same problem. And it did. I had to delete the .git directory in the client so version control doesn't think this is a submodule. From the root repository:

cd client

rm -r .git

git rm --cached .

cd ..

git add client

git commit -m "remove submodule"

git push origin main

git push heroku main 
thib
  • 68
  • 1
  • 8