Search code examples
node.jsgitheroku

Deployment on heroku failed


I want to deploy my exiting project on heroku, but it gives me an error.

structure of my file:

___instagram
  __backend
    _controllers
    _images
    _middleware
    _models
    _node_modules
    _routes
    _utiles
    .gitignore
    app.js
    package-lock.json
    package.json
    Procfile
  __ui
    ...

commands:

E:\Coding\projects\instagram>git add .

E:\Coding\projects\instagram>git commit -m "update controllers" 
[master 086d891] update controllers
 1 file changed, 1 insertion(+), 1 deletion(-)

E:\Coding\projects\instagram>cd backend
E:\Coding\projects\instagram\backend>git push -f heroku master

after the last command (git push -f heroku master) i got this error:

E:\Coding\projects\instagram\backend>git push -f heroku master
Enumerating objects: 16, done.
Counting objects: 100% (16/16), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 956 bytes | 956.00 KiB/s, done.
Total 10 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
remote:
remote:  !     ERROR: Application not supported by 'heroku/nodejs' buildpack
remote:  !     
remote:  !     The 'heroku/nodejs' buildpack is set on this application, but was
remote:  !     unable to detect a Node.js codebase.
remote:  !     A Node.js app on Heroku requires a 'package.json' at the root of
remote:  !     the directory structure.
remote:  !
remote:  !     If you are trying to deploy a Node.js application, ensure that this
remote:  !     file is present at the top level directory. This directory has the
remote:  !     following files:
remote:  !
remote:  !     backend/
remote:  !     ui/
remote:  !
remote:  !     If you are trying to deploy an application written in another
remote:  !     language, you need to change the list of buildpacks set on your
remote:  !     Heroku app using the 'heroku buildpacks' command.
remote:  !
remote:  !     For more information, refer to the following documentation:
remote:  !     https://devcenter.heroku.com/articles/buildpacks
remote:  !     https://devcenter.heroku.com/articles/nodejs-support#activation
remote:
remote:
remote:        More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to ins-app-clone.
remote:
To https://git.heroku.com/ins-app-clone.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/ins-app-clone.git'

Solution

  • Heroku buildpack looks at the top-level (root) for package.json.

    The solution here is to use git sub-trees. I too was facing this issue where I had a Monorepo MERN codebase in which I wanted to deploy my server using Heroku and client via Vercel.

    I have written a blog post regarding this, I'm sure you'll get an idea regarding a solution to this.

    Link to Blog Post