Question

Rails deployment failed: error Command "webpack" not found.

I ran into an error when deploying a Rails application. It seems that Webpack command is not found even though I have added the webpack gem to the Gemfile.

[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.520712 #777]  INFO -- : Writing /workspace/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.521501 #777]  INFO -- : Writing /workspace/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.523285 #777]  INFO -- : Writing /workspace/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.523900 #777]  INFO -- : Writing /workspace/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.527056 #777]  INFO -- : Writing /workspace/public/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.527350 #777]  INFO -- : Writing /workspace/public/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.527929 #777]  INFO -- : Writing /workspace/public/assets/stimulus.min-900648768bd96f3faeba359cf33c1bd01ca424ca4d2d05f36a5d8345112ae93c.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.528342 #777]  INFO -- : Writing /workspace/public/assets/stimulus.min-900648768bd96f3faeba359cf33c1bd01ca424ca4d2d05f36a5d8345112ae93c.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.528814 #777]  INFO -- : Writing /workspace/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.529248 #777]  INFO -- : Writing /workspace/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.529512 #777]  INFO -- : Writing /workspace/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.530051 #777]  INFO -- : Writing /workspace/public/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.530338 #777]  INFO -- : Writing /workspace/public/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.530976 #777]  INFO -- : Writing /workspace/public/assets/stimulus.min.js-5cdf38f474c7d64a568a43e5de78b4313515aa0e4bd3d13fac297fffeba809f0.map
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.533055 #777]  INFO -- : Writing /workspace/public/assets/activestorage-3ab61e47dd4ee2d79db525ade1dca2ede0ea2b7371fe587e408ee37b7ade265d.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.533897 #777]  INFO -- : Writing /workspace/public/assets/activestorage-3ab61e47dd4ee2d79db525ade1dca2ede0ea2b7371fe587e408ee37b7ade265d.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.536455 #777]  INFO -- : Writing /workspace/public/assets/activestorage.esm-01f58a45d77495cdfbdfcc872902a430426c4391634ec9c3da5f69fbf8418492.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.536971 #777]  INFO -- : Writing /workspace/public/assets/activestorage.esm-01f58a45d77495cdfbdfcc872902a430426c4391634ec9c3da5f69fbf8418492.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.537184 #777]  INFO -- : Writing /workspace/public/assets/actioncable-da745289dc396d1588ddfd149d68bb8e519d9e7059903aa2bb98cfc57be6d66e.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.537620 #777]  INFO -- : Writing /workspace/public/assets/actioncable-da745289dc396d1588ddfd149d68bb8e519d9e7059903aa2bb98cfc57be6d66e.js.gz
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.538130 #777]  INFO -- : Writing /workspace/public/assets/actioncable.esm-3d92de0486af7257cac807acf379cea45baf450c201e71e3e84884c0e1b5ee15.js
[2022-07-14 15:11:20]        I, [2022-07-14T15:11:20.538413 #777]  INFO -- : Writing /workspace/public/assets/actioncable.esm-3d92de0486af7257cac807acf379cea45baf450c201e71e3e84884c0e1b5ee15.js.gz
[2022-07-14 15:11:21]        Compiling...
[2022-07-14 15:11:23]        Compilation failed:
[2022-07-14 15:11:23]        yarn run v1.22.19
[2022-07-14 15:11:23]        info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[2022-07-14 15:11:23]        
[2022-07-14 15:11:23]        
[2022-07-14 15:11:23]        warning package.json: No license field
[2022-07-14 15:11:23]        warning package.json: No license field
[2022-07-14 15:11:23]        error Command "webpack" not found.
[2022-07-14 15:11:23]        
[2022-07-14 15:11:23] 
[2022-07-14 15:11:23]  !
[2022-07-14 15:11:23]  !     Precompiling assets failed.
[2022-07-14 15:11:23]  !
[2022-07-14 15:11:23] ERROR: failed to build: exit status 1
[2022-07-14 15:11:24] 
[2022-07-14 15:11:24] For documentation on the buildpacks used to build your app, please see:
[2022-07-14 15:11:24] 
[2022-07-14 15:11:24]    Ruby  v0.230.3  https://do.co/apps-buildpack-ruby
[2022-07-14 15:11:24] 
[2022-07-14 15:11:24]  ! Build failed
[]

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’m not 100% clear on the cause of this, but it appears some combination of Rails 7 and gems no longer automatically runs “yarn” before the assets:precompile task, so you need to ensure it’s run in order to install webpacker and your other prerequisites.

If your issue is the same as mine, you might have luck creating an initializer in, say, lib/tasks/before_assets_precompile.rake with the following content:

task before_assets_precompile: :environment do
  system('yarn')
end

# every time you execute 'rake assets:precompile'
# run 'before_assets_precompile' first
Rake::Task['assets:precompile'].enhance ['before_assets_precompile']