symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

"encore: not found" on Heroku platform #385

Closed bogdan-pistol closed 6 years ago

bogdan-pistol commented 6 years ago

I am deploying a Symfony4 app on Heroku. Everything worked fine up until it didn't anymore. Don't really know what to do.

The npm run build command seems to fail. Below is the deploy output from heroku.

Heroku runs an Ubuntu 16.04 VM.

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=false

-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 8.x...
       Downloading and installing node 8.12.0...
       Using default npm version: 6.4.1

-----> Restoring cache
       Caching has been disabled because NODE_MODULES_CACHE=false

-----> Building dependencies
       Installing node modules (package.json + package-lock)

       > uglifyjs-webpack-plugin@0.4.6 postinstall /tmp/build_7d3850ed3a97bc8e0eeec8819b398bb8/node_modules/uglifyjs-webpack-plugin
       > node lib/post_install.js

       added 863 packages from 630 contributors and audited 6764 packages in 37.65s
       found 0 vulnerabilities

-----> Pruning devDependencies
       removed 863 packages in 12.201s
       found 0 vulnerabilities

-----> Build succeeded!
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
       - php (7.2.9)
       - nginx (1.8.1)
       - apache (2.4.34)
-----> Installing dependencies...
       Composer version 1.7.2 2018-08-16 16:57:12
       Loading composer repositories with package information
       Installing dependencies from lock file
       Package operations: 88 installs, 0 updates, 0 removals
         - Installing ocramius/package-versions (1.3.0): Loading from cache
         - Installing symfony/flex (v1.0.89): Loading from cache

       Prefetching 2 packages 🎶 💨
         - Downloading (100%)

         - Installing symfony/polyfill-mbstring (v1.8.0): Loading from cache
         - Installing symfony/polyfill-ctype (v1.8.0): Loading from cache
         - Installing doctrine/lexer (v1.0.1): Loading from cache
         - Installing doctrine/annotations (v1.6.0): Loading from cache
         - Installing doctrine/reflection (v1.0.0): Loading from cache
         - Installing doctrine/event-manager (v1.0.0): Loading from cache
         - Installing doctrine/collections (v1.5.0): Loading from cache
         - Installing doctrine/cache (v1.7.1): Loading from cache
         - Installing doctrine/persistence (v1.0.0): Loading from cache
         - Installing doctrine/inflector (v1.3.0): Loading from cache
         - Installing doctrine/common (v2.9.0): Loading from cache
         - Installing symfony/doctrine-bridge (v4.1.2): Loading from cache
         - Installing doctrine/doctrine-cache-bundle (1.3.3): Loading from cache
         - Installing doctrine/instantiator (1.1.0): Loading from cache
         - Installing symfony/yaml (v4.0.6): Loading from cache
         - Installing symfony/console (v4.0.6): Loading from cache
         - Installing zendframework/zend-eventmanager (3.2.0): Loading from cache
         - Installing zendframework/zend-code (3.3.0): Loading from cache
         - Installing ocramius/proxy-manager (2.2.0): Loading from cache
         - Installing doctrine/dbal (v2.8.0): Loading from cache
         - Installing doctrine/migrations (v1.6.2): Loading from cache
         - Installing twig/twig (v2.4.7): Loading from cache
         - Installing twig/extensions (v1.5.1): Loading from cache
         - Installing symfony/translation (v4.0.6): Loading from cache
         - Installing symfony/validator (v4.0.6): Loading from cache
         - Installing symfony/twig-bridge (v4.0.6): Loading from cache
         - Installing symfony/http-foundation (v4.0.8): Loading from cache
         - Installing symfony/event-dispatcher (v4.0.8): Loading from cache
         - Installing psr/log (1.0.2): Loading from cache
         - Installing symfony/debug (v4.0.8): Loading from cache
         - Installing symfony/http-kernel (v4.0.8): Loading from cache
         - Installing symfony/filesystem (v4.0.8): Loading from cache
         - Installing symfony/config (v4.0.8): Loading from cache
         - Installing symfony/twig-bundle (v4.0.6): Loading from cache
         - Installing symfony/inflector (v4.0.8): Loading from cache
         - Installing symfony/property-access (v4.0.8): Loading from cache
         - Installing symfony/security (v4.0.8): Loading from cache
         - Installing psr/container (1.0.0): Loading from cache
         - Installing symfony/dependency-injection (v4.0.13): Loading from cache
         - Installing symfony/security-bundle (v4.0.6): Loading from cache
         - Installing symfony/routing (v4.0.8): Loading from cache
         - Installing symfony/finder (v4.0.8): Loading from cache
         - Installing psr/simple-cache (1.0.1): Loading from cache
         - Installing psr/cache (1.0.1): Loading from cache
         - Installing symfony/cache (v4.0.6): Loading from cache
         - Installing symfony/framework-bundle (v4.0.6): Loading from cache
         - Installing symfony/options-resolver (v4.0.6): Loading from cache
         - Installing symfony/intl (v4.0.6): Loading from cache
         - Installing symfony/polyfill-intl-icu (v1.7.0): Loading from cache
         - Installing symfony/form (v4.0.6): Loading from cache
         - Installing symfony/asset (v4.1.4): Loading from cache
         - Installing sensio/framework-extra-bundle (v5.1.6): Loading from cache
         - Installing pagerfanta/pagerfanta (v1.0.5): Loading from cache
         - Installing doctrine/orm (v2.6.1): Loading from cache
         - Installing jdorn/sql-formatter (v1.2.17): Loading from cache
         - Installing doctrine/doctrine-bundle (1.9.1): Loading from cache
         - Installing easycorp/easyadmin-bundle (v1.17.12): Loading from cache
         - Installing willdurand/negotiation (v2.3.1): Loading from cache
         - Installing willdurand/jsonp-callback-validator (v1.1.0): Loading from cache
         - Installing symfony/templating (v4.0.11): Loading from cache
         - Installing friendsofsymfony/rest-bundle (2.3.1): Loading from cache
         - Installing psr/http-message (1.0.1): Loading from cache
         - Installing guzzlehttp/psr7 (1.4.2): Loading from cache
         - Installing guzzlehttp/promises (v1.3.1): Loading from cache
         - Installing guzzlehttp/guzzle (6.3.0): Loading from cache
         - Installing jms/metadata (1.6.0): Loading from cache
         - Installing phpoption/phpoption (1.5.0): Loading from cache
         - Installing jms/parser-lib (1.0.0): Loading from cache
         - Installing phpcollection/phpcollection (0.5.0): Loading from cache
         - Installing jms/serializer (1.12.0): Loading from cache
         - Installing jms/serializer-bundle (2.4.1): Loading from cache
         - Installing paragonie/random_compat (v2.0.11): Loading from cache
         - Installing league/oauth2-client (2.3.0): Loading from cache
         - Installing knpuniversity/oauth2-client-bundle (v1.18.0): Loading from cache
         - Installing league/oauth2-facebook (2.0.1): Loading from cache
         - Installing ramsey/uuid (3.7.3): Loading from cache
         - Installing nikic/php-parser (v4.0.0): Loading from cache
         - Installing symfony/maker-bundle (v1.3.1): Loading from cache
         - Installing monolog/monolog (1.23.0): Loading from cache
         - Installing symfony/monolog-bridge (v4.0.6): Loading from cache
         - Installing symfony/monolog-bundle (v3.2.0): Loading from cache
         - Installing doctrine/doctrine-migrations-bundle (v1.3.1): Loading from cache
         - Installing symfony/orm-pack (v1.0.5): Loading from cache
         - Installing symfony/serializer (v4.0.11): Loading from cache
         - Installing symfony/webpack-encore-pack (v1.0.3): Loading from cache
       Generating optimized autoload files
       ocramius/package-versions:  Generating version class...
       ocramius/package-versions: ...done generating version class
       Executing script cache:clear [OK]
       Executing script assets:install --symlink --relative public [OK]

       > npm run build

       > @ build /tmp/build_7d3850ed3a97bc8e0eeec8819b398bb8
       > encore production

       sh: 1: encore: not found
       npm ERR! file sh
       npm ERR! code ELIFECYCLE
       npm ERR! errno ENOENT
       npm ERR! syscall spawn
       npm ERR! @ build: `encore production`
       npm ERR! spawn ENOENT
       npm ERR! 
       npm ERR! Failed at the @ build script.
       npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2018-09-12T19_55_40_893Z-debug.log
       Script npm run build handling the post-install-cmd event returned with error code 1
 !     WARNING: A post-install-cmd script terminated with an error
 !     ERROR: Dependency installation failed!
 !     
 !     The 'composer install' process failed with an error. The cause
 !     may be the download or installation of packages, or a pre- or
 !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
 !     in your 'composer.json'.
 !     
 !     Typical error cases are out-of-date or missing parts of code,
 !     timeouts when making external connections, or memory limits.
 !     
 !     Check the above error output closely to determine the cause of
 !     the problem, ensure the code you're pushing is functioning
 !     properly, and that all local changes are committed correctly.
 !     
 !     For more information on builds for PHP on Heroku, refer to
 !     https://devcenter.heroku.com/articles/php-support
 !     
 !     REMINDER: the following warnings were emitted during the build;
 !     check the details above, as they may be related to this error:
 !     - A post-install-cmd script terminated with an error
 !     Push rejected, failed to compile PHP app.
 !     Push failed

The composer.json file:

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "easycorp/easyadmin-bundle": "^1.17",
        "friendsofsymfony/rest-bundle": "^2.3",
        "jms/serializer-bundle": "^2.4",
        "knpuniversity/oauth2-client-bundle": "^1.18",
        "league/oauth2-facebook": "^2.0",
        "ramsey/uuid": "^3.7",
        "sensio/framework-extra-bundle": "^5.1",
        "symfony/console": "^4.0",
        "symfony/flex": "^1.0",
        "symfony/framework-bundle": "^4.0",
        "symfony/lts": "^4@dev",
        "symfony/maker-bundle": "^1.3",
        "symfony/monolog-bundle": "^3.2",
        "symfony/orm-pack": "^1.0",
        "symfony/serializer": "^4.0",
        "symfony/webpack-encore-pack": "^1.0",
        "symfony/yaml": "^4.0"
    },
    "require-dev": {
        "symfony/dotenv": "^4.0",
        "symfony/web-server-bundle": "^4.0"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts",
            "npm run build"
        ],
        "post-update-cmd": [
            "@auto-scripts",
            "npm run build"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "id": "01C99RKJ3M7493J86RBNV3BMKP",
            "allow-contrib": true
        }
    }
}
Lyrkan commented 6 years ago

Hi @bogdan-pistol,

I think you are getting that error because npm run build isn't executed at the right time.

From Heroku documentation:

By default, Heroku will install all dependencies listed in package.json under dependencies and devDependencies.

After running the installation and build steps Heroku will strip out the packages declared under devDependencies before deploying the application.

Based on you logs Heroku do a npm install which downloads all the dependencies and then directly removes the dev dependencies:

-----> Building dependencies
       Installing node modules (package.json + package-lock)

       > uglifyjs-webpack-plugin@0.4.6 postinstall /tmp/build_7d3850ed3a97bc8e0eeec8819b398bb8/node_modules/uglifyjs-webpack-plugin
       > node lib/post_install.js

       added 863 packages from 630 contributors and audited 6764 packages in 37.65s
       found 0 vulnerabilities

-----> Pruning devDependencies
       removed 863 packages in 12.201s
       found 0 vulnerabilities

And if I'm not wrong, @symfony/webpack-encore should be listed as a dev dependency in your package.json file... which means that when you try to run Encore to build your app it isn't there anymore.

To fix your issue you'll have to do your npm run build after the Building dependencies step but before the Pruning devDependencies one. I'm not using Heroku so I don't exactly know how to do that, but I'm sure that it should be explained somewhere in the documentation :)

bogdan-pistol commented 6 years ago

Wow! Great catch! For the moment i have deactivated the pruning of devDependecies via NPM_CONFIG_PRODUCTION=false Thanks for the prompt response!