Search code examples
phplaravelpostgresqlherokunumberformatter

Heroku Class 'NumberFormatter' not found


Deploying my Laravel 7 app in Heroku I get this error, it appears only in Heroku, not on my local box (localhost)

Class 'NumberFormatter' not found (View: ...)

Screenshot of Error Message

Server Details:

  • Heroku
  • PHP 7.4.12
  • Laravel Framework 7.30.4

Solution

  • The NumberFormatter classDocs requires the PHP Internationalization extension (intl)Docs, and this extension is not available built-in on Heroku Heroku Built-in ExtensionsHeroku Docs.

    Instead Heroku gives you permission to use optional extensionsHeroku Docs.

    To make use of them you can either use the composer command to require it ("ext-intl"):

    composer require ext-intl
    

    Or you can manually add this to composer.json in the require sectionComposer Docs:

    {
      "require": {
        "ext-intl": "*"
      }
    }
    

    Commit the file and push the changes to Heroku. The error should be gone until you find the next missing class.

    This is another example, why it is a good idea if you have a Composer based PHP project, to document the extensions in use as well in the composer.json file.

    When the day comes, you have them documented in the Composer JSON already.

    And systems like Heroku can benefit from it, too!