0

Once again i am a little out of my depth.

I am struggling with the deployment of my app on Heroku. I think i know 1 possible causes for my issues but I have no idea on how to fix it. I have a structure like:

|app
----|frontend
----|backend
----Procfile

My server.js file is in a "backend" folder and my build is in the "frontend", i saw somebody else on another post mention that you can't import when deployed, it would need to be caught in the build. I can't run the npm run build in the app directory though.

Within Procfile:

web: node backend/server.js

My second question is about node in the procfile? I use NPM start in my local app, is node still correct for this? Can anybody give me suggestions on how to fix this?

After creating extra config vars for the backend to be accepted heroku errors are:

2020-11-14T17:54:47.586391+00:00 app[web.1]: > notd-server@1.0.0 start /app
2020-11-14T17:54:47.586391+00:00 app[web.1]: > nodemon --watch backend --exec node --experimental-modules backend/server.js
2020-11-14T17:54:47.586392+00:00 app[web.1]: 
2020-11-14T17:54:47.591182+00:00 app[web.1]: sh: 1: nodemon: not found
2020-11-14T17:54:47.594512+00:00 app[web.1]: npm ERR! file sh
2020-11-14T17:54:47.594706+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-14T17:54:47.594847+00:00 app[web.1]: npm ERR! errno ENOENT
2020-11-14T17:54:47.594972+00:00 app[web.1]: npm ERR! syscall spawn
2020-11-14T17:54:47.595832+00:00 app[web.1]: npm ERR! notd-server@1.0.0 start: `nodemon --watch backend --exec node --experimental-modules backend/server.js`
2020-11-14T17:54:47.595924+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-11-14T17:54:47.596050+00:00 app[web.1]: npm ERR! 
2020-11-14T17:54:47.596145+00:00 app[web.1]: npm ERR! Failed at the notd-server@1.0.0 start script.
2020-11-14T17:54:47.596232+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-14T17:54:47.603840+00:00 app[web.1]: 
2020-11-14T17:54:47.604047+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-14T17:54:47.604184+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-11-14T17_54_47_597Z-debug.log

package.json

{
  "name": "notd-server",
  "version": "1.0.0",
  "description": "server side for NOTD web app",
  "main": "index.js",
  "scripts": {
    
    "start": "nodemon --watch backend --exec node --experimental-modules backend/server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Eldoddo/NOTD-Dev.git"
  },
  "author": "EDodd",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Eldoddo/NOTD-Dev/issues"
  },
  "homepage": "https://github.com/Eldoddo/NOTD-Dev#readme",
  "dependencies": {
    "body-parser": "^1.19.0",
    "dotenv": "^8.2.0",
    "express-async-handler": "^1.1.4",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.10.11"
  },
  "devDependencies": {
    "@babel/cli": "^7.12.1",
    "@babel/core": "^7.12.3",
    "@babel/node": "^7.12.1",
    "@babel/preset-env": "^7.12.1",
    "nodemon": "^2.0.6"
  },
  "engines": {
    "node": "12.4.0",
    "npm": "6.9.0"
  }
}

Much appreciated.

eldoddo
  • 3
  • 6
  • Do you have a Procfile that tells Heroku what to run? – Ozgur Sar Nov 14 '20 at 12:48
  • Yes i do, i have edited the question to show where it is located and what is in it. – eldoddo Nov 14 '20 at 13:21
  • This may answer your question. https://stackoverflow.com/questions/39197334/automated-heroku-deploy-from-subfolder . I didn't test but the answer suggests PROJECT_PATH config var set to backend – Ozgur Sar Nov 14 '20 at 13:24
  • I tried to follow; i have the current error 2020-11-14T15:44:52.067452+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=notd-react-test.herokuapp.com request_id=21e52d0d-1d54-4ec0-ba62-dbc49b94eab7 fwd="84.66.40.63" dyno= connect= service= status=503 bytes= protocol=https 2020-11-14T15:44:53.418425+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=notd-react-test.herokuapp.com request_id=28272398-208d-402d-9cda-762129a729f4 fwd="84.66.40.63" dyno= connect= service= status=503 bytes= protocol=https – eldoddo Nov 14 '20 at 15:47
  • I also had thoughts about my procfile which i put in to the main question. – eldoddo Nov 14 '20 at 16:14
  • Did you do this? >> Inside the Settings tab, you need to add a Buildpack that will tell heroku to look for your folder instead of deploying the repo root. – Ozgur Sar Nov 14 '20 at 16:17
  • So i added https://github.com/timanovsky/subdir-heroku-buildpack to my buildpacks and set a config var for PROJECT_PATH to be backend, then i needed a package.json file, so i moved the package file in to the backend folder rather than top level – eldoddo Nov 14 '20 at 17:49
  • So, did it work? – Ozgur Sar Nov 14 '20 at 17:54
  • unfortunately not, i have added the errors to the question edit, thank you for helping – eldoddo Nov 14 '20 at 17:58
  • Can you check your package.json? Maybe you installed nodemon as a dependency. Normally it should be dev dependency. – Ozgur Sar Nov 14 '20 at 18:33
  • So nodemon is in my packaage.json in devDependencies, do i need to delete this section? – eldoddo Nov 15 '20 at 20:55
  • No if it is in devDependencies it can stay – Ozgur Sar Nov 15 '20 at 20:57

0 Answers0