Hello. I’m evaluating the app platform to see if we can migrate our Ruby on Rails app to here from Heroku. I tried adding npm install as a build command, and I can see it output in the logs while building the app, but it doesn’t appear to be succeeding as we’re getting an error while precompiling assets. The missing asset is one that gets installed via npm. So, my question is: what is the “correct way” to do an npm install before a Rails app precompiles assets? Do I need to add commands to install nodejs and npm (I’ve tried this to no avail)? Thanks

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer

@vianettim 👋

The ruby/rails buildpack will automatically install node modules and run assets:precompile as part of the build process. Currently npm isn’t available by default in that image, just yarn for now, which we’re tracking internally and plan to address. In the meantime, if you need to interact with node, you should use yarn instead of npm.

Alternatively, if you need a more flexible or customized environment, you can build with a Dockerfile.

Thanks for using the App Platform — happy coding!

  • “The ruby/rails buildpack will automatically install node modules and run assets:precompile as part of the build process.”
    It doesn’t seem to be doing this for our app, considering we’re getting an error on precompile that it can’t find the assets that exist in package.json. I tried adding a yarn install to the build commands, but am unsure if it is actually doing anything, since there is no output from the command:

    | 13:00:42 => Configuring custom build command: yarn install
    | 13:00:42 => Configuring custom run command: bundle exec puma -C config/puma.rb
    | 13:00:43 => Running Buildpack detection
    | 13:00:43 
    | 13:00:43 heroku/ruby                 0.0.1
    | 13:00:43 digitalocean/ruby-appdetect 0.0.2
    | 13:00:43 digitalocean/procfile       0.0.3
    | 13:00:43 digitalocean/custom         0.1.0
    | 13:00:43 
    | 13:00:43 => Building Buildpack app
    | 13:00:43 
    | 13:00:43 -----> Installing bundler 2.0.2
    | 13:08:14        Bundle completed (444.37s)
    | 13:08:14        Cleaning up the bundler cache.
    | 13:08:16 -----> Installing node-v12.16.2-linux-x64
    | 13:08:23 -----> Detecting rake tasks
    | 13:08:39 -----> Preparing app for Rails asset pipeline
    | 13:08:39        Running: rake assets:precompile
    | 13:08:42        [tunemygc] not enabled
    | 13:08:51        Yarn executable was not detected in the system.
    | 13:08:51        Download Yarn at https://yarnpkg.com/en/docs/install
    | 13:08:52        I, [2020-10-14T20:08:52.940164 #2415]  INFO -- : Writing /workspace/public/assets/disable_animations-876051af5339dca677a49984ab565dd4ea5242b646c43b3400b669ddf881688c.css
    | 13:08:52        I, [2020-10-14T20:08:52.942642 #2415]  INFO -- : Writing /workspace/public/assets/disable_animations-876051af5339dca677a49984ab565dd4ea5242b646c43b3400b669ddf881688c.css.gz
    | 13:08:53        I, [2020-10-14T20:08:53.633437 #2415]  INFO -- : Writing /workspace/public/assets/mailer-efd29798b355d7f1ac52cfd32cba0f064e3fbdfa8c2bf5adcc2682969b396bda.css
    | 13:08:53        I, [2020-10-14T20:08:53.634069 #2415]  INFO -- : Writing /workspace/public/assets/mailer-efd29798b355d7f1ac52cfd32cba0f064e3fbdfa8c2bf5adcc2682969b396bda.css.gz
    | 13:08:53        rake aborted!
    | 13:08:53        Sprockets::FileNotFound: couldn't find file 'croppie/croppie' with type 'application/javascript'

    Any ideas as to how to proceed, or would I need to switch to building with a Dockerfile?

    • That’s definitely strange. We’ll take a look at this internally and fix this buildpack to properly include yarn and npm. In the meantime, your best option is probably to use a Dockerfile. Thanks for your patience on this.

      • Just as an update on our status: I was able to achieve a successful deployment. At first, our package.json specified Node v10, so I tried updating that to v12 to no avail. There was an issue with our package.json compiling dependencies, failing on v8, so I resolved that issue. App Platform deploy still failed. I replaced all modules in package.json with Ruby gems, and copied the assets that didn’t have gems directly into the project, and that resulted in a successful deployment.

    • Does the app include the webpacker or execjs gem? The buildpack currently installs node/yarn only if one of these gems are included.

Submit an Answer