rails7 RAILS_ENV=production rails assets:precompile error Command "build" not found

1.1k Views Asked by At

Extremly odd error, asset precompilation works fine in dev mode, but as soon as i do production mode, i get error:

root@53407ec15126:/app# RAILS_ENV=production rails assets:precompile
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.04s.
yarn run v1.22.18
error Command "build" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rails aborted!
jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors

Tasks: TOP => assets:precompile => javascript:build
(See full trace by running task with --trace)
root@53407ec15126:/chinese-flashcards-app#

And the weirdest thing is, i dont even use yarn in my project(i use importmaps).

2

There are 2 best solutions below

0
On BEST ANSWER

Well.. I figured out how to do a monkey patch(Sigh..).

Add this to package.json:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "echo 1",
    "build:css": "echo 1"
  },

This does not resolve the issue of rails prod preprocessor using yarn/npm tho(i dont need them).

0
On

Thanks IvRRimUm I've been searching for this fix for ages. Make sure your importmaps and if you're using rails 7 ensure that is set up properly also. I found these guides useful:

https://www.learnenough.com/blog/migrating-away-from-rails-webpacker https://eagerworks.com/blog/import-maps-in-rails-7