Search code examples
node.jsherokuweb-deployment

Unable to git push my node.js server to Heroku, says no bower.json present


I am developing a Node.js server for my MERN application and trying to deploy the server on Heroku. However, after I followed the usual commands on Heroku's page for my app, and run git add ., git commit -am "Deploy commit", and git push heroku master, it wasn't able to successfully push the commit.

I have attached my package.json and log file below.

My package.json file:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "bower install && grunt build",
    "start": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "bower": "^1.8.13",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "express": "^4.17.2",
    "mongoose": "^6.1.2",
    "multer": "^1.4.4",
    "nodemon": "^2.0.15",
    "path": "^0.12.7"
  },
  "engines": {
    "node": "16.x",
    "npm": "8.x"
  }
}

My logfile:

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       
-----> Installing binaries
       engines.node (package.json):  16.x
       engines.npm (package.json):   8.x
       
       Resolving node version 16.x...
       Downloading and installing node 16.13.1...
       Bootstrapping npm 8.x (replacing 8.1.2)...
       npm 8.x installed
       
-----> Installing dependencies
       Installing node modules
       
       > server@1.0.0 postinstall
       > node ./node_modules/bower/bin/bower install
       
       bower                           ENOENT No bower.json present
       npm ERR! code 1
       npm ERR! path /tmp/build_c71e20e4
       npm ERR! command failed
       npm ERR! command sh -c node ./node_modules/bower/bin/bower install
       
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.nktzc/_logs/2022-01-01T10_48_31_122Z-debug-0.log
-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

After encountering the above error, I added a registry for my .bowerrc file like so:

{
  "registry": "https://registry.bower.io"
}

Even this hasn't been really helpful. How can I fix this?


Solution

  • After a bit of research, I got the build success message. Here's what I did to get it working:

    1. So the first thing I did was npm install bower-json.
    2. After that, I used bower init and initialized the app.
    3. Then I removed the build under scripts in package.json.
    4. Following this, I went for another git add, git commit, and git push heroku master.

    This process got my build successful!