Deploy a Strapi API on Heroku in 5 min

Our community is looking for talented writers who are passionate about our ecosystem (jamstack, open-source, javascript) and willing to share their knowledge/experiences through our Write for the community program.


This is a companion discussion topic for the original entry at https://strapi.io/blog/deploying-a-strapi-api-on-heroku

Hello, I followed the instructions provided in the tutorial, but after i deploy it to Heroku and click view it just shows the “Application error” screen.

Checking the logs shows me H10 error codes which means that the application crashes. I tried numerous times with projects in both Europe and the U.S servers but the result is the same. I haven’t altered anything in my strapi and followed the tutorial step-by-step. Is there any way to fix this?

Thank you

2 Likes

Deploy the Strapi React Blog starter to Netlify.

  1. Connect your Github account to Netlify.
  2. Enter your Strapi instance URL in the API_URL field.
  3. Your deployed Strapi-powered React blog.
  4. Articles listed in the Strapi UI.
  5. Article creation in the Strapi UI.
  6. The new article is visible on the deployed site.

I am facing the same problem. Have you found the solution?

I also got the same issue.

2022-02-05T14:40:57.887822+00:00 heroku[web.1]: Process exited with status 1
2022-02-05T14:40:57.994003+00:00 heroku[web.1]: State changed from starting to crashed
2022-02-05T14:40:59.282556+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=

You need pass a placeholder for APP_KEYS, for example: testKey1, testKey2 to the CONFIG VAR in heroku

./config/env/production/server.js

module.exports = ({ env }) => ({
  url: env("MY_HEROKU_URL"),
  proxy: true,
  app: {
    keys: env.array("APP_KEYS", ["testKey1", "testKey2"]),
  },
});
3 Likes

I have tried deploying my project to Heroku and got this error have anyone have a solution
remote: ModuleNotFoundError: Module not found: Error: Can’t resolve ‘@strapi/design-system/Carousel’ in ‘/tmp/build_7a488f6f/node_modules/@strapi/plugin-upload/admin/src/components/MediaLibraryInput/Carousel’

I have followed this tutorial but my information is not saved to db and I have to create all the content anew after pushing updates to schema/collections from GH. Also, I cannot get API access to the content, which is really frustrating, lol.

View Logs and then restart dynos, then we can see the actual error msg.
You can search that error msg to solve your problem.

![ViewLogs|690x443](upload://6u4RFG5q0HkVpTVM68vHlqF6Z6y.png)

You can fix this issue by adding app keys for your production deployment. You can add it to your heroku config vars:

  1. In heroku, go to your app → settings → config vars
  2. Add a new variable with the name APP_KEYS and for values, a comma seperated list of secure keys, e.g secure1,secure2. But use actually secure randomly generated strings

The app should automatically redeploy when updating the config vars if you turned on automatic deploys, if not deploy manually and that should work

1 Like

you should try to find and remove .env in .gitignore file.
commit code and try again

4 Likes

Thanks a lot!! It resolved my error

For anyone who’s still having this issue as of March 2022, the official Strapi v4 docs have not been updated to support the fix. The following solution worked to fix my issue, the same as OP’s.

Per @iamjulian’s answer (via StackOverflow), here is a specific example of how I solved this with two randomly generated secret keys.

  1. On my Mac, I ran the following terminal command a total of 2 times. This command generates a random alphanumeric string that’s 16 characters long. (Running this twice gives you two different random strings.) Example output: afe7405d67f206b6
openssl rand -base64 8 | md5 | head -c16; echo
  1. With your 2 keys (e.g. afe7405d67f206b6 and 63e90c0711630990), add a new Heroku Config Var to your app with key: APP_KEYS, value: (your two secret keys separated by a comma , (no space), e.g. afe7405d67f206b6,63e90c0711630990

  2. In your config/env/production/server.js file, here is an example of how this will look:

module.exports = ({ env }) => ({
	url: env('APP_URL'),
	proxy: true,
	app: {
		keys: env.array('APP_KEYS', ['afe7405d67f206b6', '63e90c0711630990'])
	}
});

I’ll leave the true reasoning behind why this works for someone who actually understands it. It seems to me that entering these secret keys directly into the codebase completely nullifies any sense of secrecy for these keys… Maybe we’re supposed to add config/env/* to our .gitignore?

At the end of the day, it works. However, at very least, this absolutely should be in the official Strapi v4 docs for Heroku deployments. To whomever on the Strapi team is responsible for this: please consider updating the docs to include this (or a different, officially supported solution).

Thanks to everyone who contributed to this answer!

3 Likes

Thank you so much! this worked

Was running into the same issue - and this worked perfectly. Thank you so much!

Application error

An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

the installation documents is a complete problem, we have tried it on different platforms such as google engine, heroku, aws and it is a total problem, the documentation is not correct, we lost a week of the whole team trying to install it, and we found a solution a lot more effective calling the information from the database in json, it is much more flexible and scalable, even wordpress with woocommer is much easier to use and scale, strapi is going to stop being used because of how complex it is to install on servers and not very scalable. there are better technologies like firebase.

If anyone else is using Strapi v4.1.8 and is getting error with missing jwtSecret, just downgrade strapi dependencies in package.json to 4.1.7, delete yarn.lock and package-lock.json and deploy it again to heroku… Just spent 3 hours to find a solution for this…

I wrote here, its same question: Missing JwtSecret error while deploying on heroku

The Heroku deployment guide was recently updated. Heroku Deployment - Strapi Developer Docs

Depending on the version of Strapi you started with, and if you push your local secrets to Heroku, make sure there is no space in the JWT admin key in the .env file. If there is your env variables in Heroku will not be populated correctly.

1 Like