Why does Heroku fail to detect Node.js buildpack? - node.js

I git cloned a Node.js application (the version specified in the package.json being 4.1.2 and that of my local machine being 6.2.2) and tried to git push on Heroku. But it failed to build and gave this error:
Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
Now I set the buildpack to heroku/nodejs and I get this message:
Buildpack set. Next release on lit-badlands-92088 will use heroku/nodejs.
Run git push heroku master to create a new release using this buildpack.
Now when I run git push heroku master, I am again told:
remote: -----> Failed to detect set buildpack
https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
remote: More info:
https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to lit-badlands-92088.
What could be the possible reasons for the Node.js buildpack not being detected even if I set it?

This means that a package.json file isn't checked into the root of your git project, so Heroku is detecting that it isn't a Node.js app. You can see this locally:
git show master:package.json
To fix it, you'll want to be sure there is a package.json in the root of your project (where there is also a .git directory), and add it to git:
git add package.json
git commit -m 'track package.json'
The phrasing ('failed to detect set buildpack') could be improved. It should probably say 'failed to detect Node.js app'. When the buildpack's "detect" script is run (https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect), it looks for a package.json file to verify that there's a node app available to build.

It’s because Heroku thinks you are deploying a Node app. But what you are deploying is the public directory of a Node app, not Node code.
Heroku uses buildpacks to select how the app is handled. You want to clear that Node association:
heroku buildpacks:clear # clear all buildpacks set on the app
Which means that “Next release will detect buildpack normally.”, that should solve it for you.
ref: https://devcenter.heroku.com/articles/buildpacks

I had similar issue, here are the steps which solved the problem.
heroku buildpacks:set heroku/nodejs
git push heroku master
Basically details are in the more info link -
This situation may also occur if you remove or rename a file that previously led to the automatic detection of your application type and thus the automatic setting of the detected buildpack on your application.

If you are working on a branch, you need to set master to track your branch
git branch -f --track master origin/branch_name
Check for package.json in master
git show master:package.json
If it's available, trying pushing again.
git push heroku master
`

Some tiny clarifications on other answers:
The error "Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz" or anything similar, means to say the GIT COMMIT you are trying to push to heroku was not DETECTED as a node.js app. (Note the capitals for subtleties).
I recently made a stupid mistake that made me aware of this: Running "ls -a" showed that my package.json and .git files were in the same root directory, as required by heroku. EXCEPT that the package.json file WAS NOT included in my latest git commit. Running "git status" alerted me that package.json was an untracked file. So I added it, and ta-da, pushing to heroku worked.
If you get an error related to buildpack, check that your GIT COMMIT has a package.json file in the root directory. If this is true, try manually specifying the buildpack with "heroku buildpacks:set heroku/nodejs" (or your desired language). This should resolve most errors related to buildpack detection.

Most apps have at least one of these signatures present, so if you see this error, it usually means an important file isn't checked into your git repository:
Java: pom.xml
Ruby: Gemfile
Node.js: package.json
Python: requirements.txt / setup.py / Pipfile
PHP: composer.json / index.php
You should:
git add {file}
git commit -am 'added {file}
git push heroku master

I run into the same issue and tried everything, eventually realized no file would commit because they were already committed and pushed to the github repository.
So you need to do the following:
Remove old git. folder:
rm -rf .git
Create new git:
git init
Add all project files:
git add .
Commit:
git commit -m “commit name”
Creat new heroku application:
heroku create
Push code to master:
git push heroku master
This worked for me.

I add Pakage.json file, and then
Remove old git. folder:
rm -rf .git
Create new git:
git init
Add all project files:
git add .
Commit:
git commit -m “commit name”
Creat new heroku application:
heroku create
Push code to master:
git push heroku master
App successfully deployed on heroku.

Related

Heroku applications and building process

I have just one question:
Why when you push to heroku, it do same all tasks to execute app?
For example I just modified one file index.js, ok, I need to git add index.js, git commit -am "Message" and heroku push origin master, but when I'm pushing to heroku, it pushing one file but do a lot of unnecessary things like
Again installing Node
Again installing dependencies (node modules), there are the same but heroku again download all dependencies
Again build cache of node modules
Why Heroku can't analyze package.json and do not install again new modules? Why it installs again Node if in Procfile I have the same web: npm run server? These actions are eating a lot of time and resources, I'm don't understand that.
you can create a ci/cd pipeline and deploy directly from your github page

Heroku deployment fails over yarn.lock file that doesn't exist

I keep getting the "Two different lockfiles found" error when trying to deploy to Heroku
remote: Building source:
remote: ! Two different lockfiles found: package-lock.json and yarn.lock
remote: Both npm and yarn have created lockfiles for this application,
remote: but only one can be used to install dependencies. Installing
remote: dependencies using the wrong package manager can result in missing
remote: packages or subtle bugs in production.
I've found a few threads on here that have the same issue except...
I don't have a yarn.lock file to remove.
If I run the commands suggested in this thread:Heroku build failing due to Yarn and npm lockfile conflict, I just get a message saying there isn't a file to remove. I'm checking the repo and my files in vsCode and i don't see a yarn.lock file so why does Heroku think I have a yarn.lock file?
SOLUTION: I found out that I had configured the heroku project to auto deploy based on my commits to the repo on Github. I guess the error message I was receiving wast he only one that applied when I was trying to manually push to heroku and i wasn't supposed to. If you run into this check you heroku settings, if you have auto deploy this situation may come up.
Just in case... when you type git push heroku master be sure you're master Branch doesn't have two lockfiles in it. If you are a on another Branch just try git push heroku <your branch name you want to push>

How to clean cache in heroku after installing dependencies?

Topic : Heroku
Problem : After installing my node js application in heroku, I made some changes in package.json. Now, when I am trying to push changes again, new dependencies are not getting installed. Heroku is picking the dependencies from cache.
How to disable cache in heroku ?
Thanks all for responding.
After much googling and spending time on my issue, I was able to solve my problem.
I thought it would be better to post an answer if anyone faces the similar dilemma.
Below is the documentation, where I found my answer https://devcenter.heroku.com/articles/nodejs-support
By default, in heroku production is set to true. That's why only dependencies get installed. ( & skips devDependencies )
heroku config:set NPM_CONFIG_PRODUCTION=false
Set production to false, to force heroku to install all packages.
** Only do this if doing development.
Heroku, by default, caches all the dependencies, so that the deployment is faster.
heroku config:set NODE_MODULES_CACHE=false
$ git commit -am 'disable node_modules cache' --allow-empty
$ git push heroku master
** Preferable only if new dependencies are added in package.json
I'm aware of answering this question now is too late but no wonder someone will need to solve this issue at anytime...
Anyways, you can clear the build cache of an app easily by installing heroku-builds plugin.
Installation:
heroku plugins:install heroku-builds
Usage:
heroku builds:cache:purge -a your-app-name
Note:
The cache will be rebuilt on the next deployment. If you do not have any new code to deploy, you can push an empty commit.
$ git commit --allow-empty -m "Purge cache"
$ git push heroku master

How to compile Bootstrap from source as part of build process on heroku?

I am building a simple node app and using Bootstrap to style my frontend. I want to deploy the app to Heroku by loading it from the GitHub repository. I don't want to put any compiled CSS/JS files in the repository, which means that they need to be compiled on Heroku after the source is pulled from GitHub.
The problem: Bootstrap's default package.json has its build dependencies in devDependencies, so the dependencies will not be installed on Heroku, which runs npm install in production mode.
Specifically, the problem comes up in my postinstall script, which consists of cd node_modules/bootstrap && npm install && ../.bin/grunt dist. My own npm install command does not end up installing anything because the overarching npm install --production is ignoring Bootstrap's devDependencies.
What is the best workaround to get Bootstrap's dependencies to be installed locally? I'm open to changing my workflow as long as (1) I don't have to put compiled files in my source repository and (2) I can still run the main npm install in production mode.
EDIT: Unless someone can think of a better solution, I think my options at this point are as follows:
Build a custom Github fork of Bootstrap that has its dependencies in dependencies instead of devDependencies
Build a custom Heroku buildpack that somehow leaves Bootstrap's dependencies intact
Abandon principle and compile Bootstrap locally, and put the compiled files in my source
Just use Heroku in development mode (obviously not a good idea)
I think I'm going to try for option 1, and go for option 3 if that fails. I'd still be interested in hearing any other ideas that people come up with.
I would look into using postinstall. The official documentation is on Heroku here.
Since you're doing some build steps at deploy time, you need some devDependencies (bootstrap sources in your case), but heroku will only install in production mode, like you said.
When connected with the heroku toolbelt client, run :
heroku config:set NPM_CONFIG_PRODUCTION=false
You'll have your devDependencies and you'll be able to build.
You only have to do that once (no need to do that each time you deploy).
PS: I don't know about your project, but maybe you need to put the NODE_ENV to production, here is the command:
heroku config:set NODE_ENV=production
You don't need yo put back the NPM_CONFIG_PRODUCTION flag back to true, this is the purpose of making the build on heroku.
But if you prefer, here is the workflow you could use (you said you were opened to change workflow):
ignore dist folder from your source repo (it should already be ignored)
make dist folder a git repo & add the git remote of heroku in repo of the dist folder
cd dist
git init
git remote add origin git#heroku.com:project-name.git
git pull origin master
make sure your build routine doesn't remove this /dist/.git folder - you can use the following glob (if you're using rimraf or something like it with grunt/gulp or whatever) : ['/dist/**/*','/dist/!.git/**/*']
This way, your workflow will be:
build (with your tool)
cd dist
git add .
git commit -m "new version bundled"
git push origin master there, you are in dist folder where origin is the remote for your heroku
You might do the same kind of things with github pages ...

Missing steps in heroku app renaming

I am on the heroku documentation. I am pushing my node app to heroku and it was working fine but I need to change the website name. https://devcenter.heroku.com/articles/renaming-apps
It shows me that I can rename my app very simply
heroku apps:rename newname
Step 2: I just change it on git and I was good to go on the heroku site.
git remote rm heroku
heroku git:remote -a newname
I did the next steps for git and received
! `git:` is not a heroku command.
a app not found when I tried to push to the the heroku master. Is there another step that I am missing?
Maybe you have an older version of the heroku client installed. What do you get when you run heroku version? The heroku git:remote -a command works with the latest version:
$ heroku version
heroku-toolbelt/3.37.2 (x86_64-darwin10.8.0) ruby/1.9.3
heroku-cli/4.19.28-8f2bd89 (amd64-darwin) go1.4.2
If you are seeing an older version run heroku update and try again.

Resources