Report this

What is the reason for this report?

How to install Node modules on app platform in Rails app

Posted on October 8, 2020

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



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

I had the same issue and the same hypothesis. Upon further inspection, I noticed a tiny little error in the log.

error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

That’ll do it! I tried running yarn install --frozen-lockfile locally and, indeed, it failed. The digital ocean buildpack appears to continue building if that fails, though, and goes on to run rake assets:precompile.

The solution was to run yarn install locally, which updated yarn.lock, then redeploy.

@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 developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.