0
votes

Heroku is not letting me start the application as it stays on for a few seconds, and then this happens:

2020-04-07T23:11:35.586817+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-07T23:11:35.597942+00:00 heroku[web.1]: State changed from crashed to starting

After that, Heroku restarts the application, and the above code is displayed one more time (this time there is no restart, just a crash).

2020-04-07T23:12:38.593514+00:00 heroku[web.1]: State changed from starting to crashed

I've searched for problems in my code, and I could not found any, so I deleted everything, and make my main file core.js a single discord bot, that just send an embed message with a title:

const { Client, MessageEmbed } = require('discord.js')
const client = new Client()
let channel = null

client.on('ready', () => {
  console.log(`bot ${client.user.tag} running`)
  channel = client.channels.cache.find(ch => /generic_channel_name/.test(ch.name))

  const embed = new MessageEmbed()
    .setTitle('Commom title')
    .setColor('#ffff00');
    channel.send(embed)
})

client.login(config.token)

Even a single setInterval causes the Heroku to crash the app:

setInterval(() => {
  console.log('Testing')
}, 3000)

I really tried lots of things, but the only thing I did that didn't crash was a simple for loop from 0 to 100.000

Can someone help me?

3

3 Answers

0
votes

There are a lot of reasons why it could happen, The most common ones are :

1. You do not have a Procfile.
Solution for this: make a Procfile which just says `worker node core.js` or `worker node .`.
2. You do not have enabled node dyno from the Heroku site.
Solution for this: Head to Dynos and enable node.
3. You have not updated your package.json.
Solution for this: Head to console/terminal and then say `npm init` and fill whatever it asks you to fill, Make sure that dependencies are properly aligned.

Sorry if this fails to help you.

0
votes

Looking at your logs, there's a 60 second difference between starting and crashed, which could mean your app is hitting the Heroku runtime 60 second Dyno boot timeout (https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout). If this is happening, you should also be seeing R10 errors in your log stream. There are many reasons why Dynos could fail to boot, but the most likely is usually that your server is not correctly binding the $PORT environment variable, which means the Heroku Routers can't determine if your app is running or not.

0
votes

I discovered the problem. My Procfile's content was web: node example/path, so I just changed it to worker: node example/path, deleted my Heroku's application, recreated it and tried again. I also made sure that in Heroku's "Resources" tab, the "web" option was deactivated, and the "worker" option was activated. This Heroku's steps plus only one word change (web to worker) changed everything, and now things are working fine.

Thank you for your time and answers