How to install Node modules on app platform in Rails app

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

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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 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!