Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assets:precompile causes Propshaft::MissingAssetError (dev & prod) #84

Closed
ghost opened this issue Mar 12, 2022 · 8 comments · Fixed by #85
Closed

assets:precompile causes Propshaft::MissingAssetError (dev & prod) #84

ghost opened this issue Mar 12, 2022 · 8 comments · Fixed by #85

Comments

@ghost
Copy link

ghost commented Mar 12, 2022

Environment

  • Rails 7.0.2.3
  • Ruby ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]
  • Bundler 2.3.9
  • Propshaft 0.6.4

Problem
As far as I understand Propshaft has two ways to resolve assets: dynamically and statically. Dynamic is the preferred way for development and static the way for production as assets get precompiled to public/assets.

Now, I recently deployed my project to Heroku and noticed that it crashes immediately as I visit the URL. Upon checking logs I noticed the following error message:

Propshaft::MissingAssetError in Home#index
The asset 'tailwind.css' was not found in the load path.
...

I double checked on Heroku and confirmed that the public/assets folder was correctly created. I also took a look at the .manifest.json and found no problems. I tried to reproduce the problem locally by running rails assets:precompile and voilà: same error message and same behavior (i.e. public/assets and .manifest.json look fine).

I noticed that this problem isn't specific to tailwind.css as stated in the error message - it seems to be any asset really. Oddly enough, upon rails assets:clobber everything works fine again locally as Propshaft switches back to the dynamic resolver.

Please note, this is fairly fresh rails project (about a week old) and I have not changed the default config in development.rb, production.rb and application.rb - yet I am unable to get the project to work properly after a rails assets:precompile.

What am I missing?

(I've attached a full stack trace just in case)
stack_trace.log

@brenogazzola
Copy link
Collaborator

I will need more information to help.

1 - Which css gem are you using? cssbundling-rails, dartsass-rails, or tailwind-rails?

2 - When you say the manifest file has no problem, do you mean that it has an entry for tailwind.css file?

3 - Is tailswind.css file in the public/assets folder after precompile?

@ghost
Copy link
Author

ghost commented Mar 12, 2022

@brenogazzola thanks for looking into it!

Below the information

  1. tailwindcss-rails 2.0.8-arm64-darwin
  2. correct, this is what the manifest looks like after a rails assets:precompile
{"tailwind.css":"tailwind-fb954058e5fd6a4053212d3556fa206f22302e90.css","backgrounds/bank-note.svg":"backgrounds/bank-note-50af140247e3439021747435ae92c3fd80e32f19.svg","backgrounds/undraw_no_data.svg":"backgrounds/undraw_no_data-0c5103bc939b8a036c3843619f98420dfc43de2a.svg","backgrounds/circuit-board.svg":"backgrounds/circuit-board-3d78da3974a2290c319c15e7034bd9dbd8450bb9.svg","backgrounds/undraw_alert.svg":"backgrounds/undraw_alert-b085948b5447f62750d4131c93e60e8405a138d2.svg","backgrounds/graph-paper.svg":"backgrounds/graph-paper-32da6b2f96dba9c94727a2cafec73a5f38b3d66a.svg","backgrounds/falling-triangles.svg":"backgrounds/falling-triangles-2f52a5b6f9dc00502def4eaf5ef8b4c9dfc461d9.svg","application.tailwind.css":"application.tailwind-d0d91abd3e76a75273408065798334439ec3368e.css","application.css":"application-2d04d1b749c0e0e5100489b3b423c9b8ce2e27e4.css","Inter-italic.greek.var.woff2":"Inter-italic.greek.var-0237d2cb53480f610892ca60df2a312ef229dc78.woff2","Inter-roman.latin.var.woff2":"Inter-roman.latin.var-f4cf732763710b1578dcb10fada6484284e39ac3.woff2","Inter-italic.vietnamese.var.woff2":"Inter-italic.vietnamese.var-b86af8f080cf435b6679bdc2fe5d01e67a73d968.woff2","Inter-roman.cyrillic.var.woff2":"Inter-roman.cyrillic.var-617f83b242b64f68afd70903d382f0f6305bb590.woff2","Inter-roman.greek.var.woff2":"Inter-roman.greek.var-500924034d991abcee1c493af565badbc214a4bc.woff2","Inter-roman.alternates.var.woff2":"Inter-roman.alternates.var-384656f1c6ce84130f8b902cf5267bd17eec995c.woff2","Inter-italic.latin.var.woff2":"Inter-italic.latin.var-26f4216faef913a69714ee7d28f12d31a71bc224.woff2","Inter-roman.vietnamese.var.woff2":"Inter-roman.vietnamese.var-ecac6871adf22786ac28da931b7b570f75a71654.woff2","Inter-italic.symbols.var.woff2":"Inter-italic.symbols.var-94f0c2bd9453870b21f4a1b633a8818dbe41f3b1.woff2","Inter-italic.extra.var.woff2":"Inter-italic.extra.var-6a679c243c7a75b26fe6bdb7f8b2e56124007945.woff2","Inter-roman.symbols.var.woff2":"Inter-roman.symbols.var-fc6b8addd3e8a0040c87cb153662ec54b706ba32.woff2","Inter-italic.latin-ext.var.woff2":"Inter-italic.latin-ext.var-90bd98d581429f8b459a71219968bf188f1f0989.woff2","Inter-italic.alternates.var.woff2":"Inter-italic.alternates.var-6a679c243c7a75b26fe6bdb7f8b2e56124007945.woff2","Inter-roman.latin-ext.var.woff2":"Inter-roman.latin-ext.var-c2fb49f067b59023e4a2b00a567458529bbd92fa.woff2","Inter-italic.cyrillic.var.woff2":"Inter-italic.cyrillic.var-b860a9d06fa7dc1f844a2343a096762d1b5513a0.woff2","Inter-roman.extra.var.woff2":"Inter-roman.extra.var-384656f1c6ce84130f8b902cf5267bd17eec995c.woff2","inter-font.css":"inter-font-5d03f6e514e09bb762620f3f1d38145a16f6504f.css","stimulus.min.js":"stimulus.min-18eaacc58b7827f3729d07fff0094620e22f9c20.js","stimulus.js":"stimulus-33b5690d111cc0620be9dd1b12e236dacf03a024.js","stimulus.min.js.map":"stimulus.min.js-787cb4d685ae9a10466252272464074f1215b5a9.map","stimulus-importmap-autoloader.js":"stimulus-importmap-autoloader-8678f88c061b2304855da698756b741391e08db4.js","stimulus-autoloader.js":"stimulus-autoloader-f0ebf72276e8a3370cc9bf4bb5888307b3d4bb02.js","stimulus-loading.js":"stimulus-loading-e367296568a6df104dc84fcfe5d1aafae5076fc0.js","turbo.min.js.map":"turbo.min.js-be482c12399498cf96dfffc770008c5c80f46f68.map","turbo.js":"turbo-584e11f34371796122a0100de30f21d9a7e4af20.js","turbo.min.js":"turbo.min-2e103ccc37abc7e592e309b1e6fa6aab152c8c99.js","es-module-shims.js.map":"es-module-shims.js-3a66b10e1bd5dc914a9eb8dd80ffd6d9b606d3ea.map","es-module-shims.js":"es-module-shims-6a29d1d0b1d1409eca0af6175eb03f8e14cffc55.js","es-module-shims.min.js":"es-module-shims.min-5ae73ca96350ef69888fc88e45277f783c0be43b.js","action_cable.js":"action_cable-a21b4532ea1400611d408e8375c5c42a35c11199.js","actioncable.esm.js":"actioncable.esm-850276fc683d4c874d6c73f5ed0954f24f5bf389.js","actioncable.js":"actioncable-121775e39ad4dc481c68abee9955c60b0b1ff7d6.js","actiontext.js":"actiontext-92c50511824a8ff9a235f6e1ee2e9627b9bd0f27.js","trix.js":"trix-c9e1c067e4bfaad3fb2c0e4d65b5b11115fc3f6a.js","trix.css":"trix-f84c5ee27b3a44e58ee790d379e9bb11624891e2.css","activestorage.esm.js":"activestorage.esm-852e4c97bb3b9e7a957506bc1993528ae91843a5.js","activestorage.js":"activestorage-14ce7a0eac3f16a2135c9bda5402d49953c1a3bc.js","rails-ujs.js":"rails-ujs-c3b690f9b8614cb5b5611b669cbf480235543f71.js","application.js":"application-71cc3ac8c00a1b68a53eca7aa49b154c8a5d858b.js","controllers/index.js":"controllers/index-a60852f1edb9abac18231d32c970b5d1d066dc74.js","controllers/application.js":"controllers/application-dd6ee432f25b60298ff91381e781b92a7f218ff6.js"}
  1. It is. The name even matches the digest-stamp in the manifest.

CleanShot 2022-03-12 at 14 06 18@2x

The stylesheet_link_tag is unchanged as far as I can tell - that's why I am unable to figure out what the problem is.

<head>
  <%= display_meta_tags site: "My Title", reverse: true %>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>
  <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>

  <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
  <%= javascript_importmap_tags %>
</head>

@brenogazzola
Copy link
Collaborator

brenogazzola commented Mar 12, 2022

Yeah, everything looks fine. When you run precompile does the build folder already exist?

(Build folder must exist at all times and be commited to the repo. Just the folder, not the files inside).

If yes, do you think you can provide a minimal project that contains the error? I’ll debug to figure out what’s broken.

@ghost
Copy link
Author

ghost commented Mar 12, 2022

Yeah, the build folder exists and is committed into VCS - contents are ignored.

@brenogazzola you should've received access to the project I'm having trouble with. I appreciate you looking into it!

@brenogazzola
Copy link
Collaborator

brenogazzola commented Mar 13, 2022

@brueggemann-erik Found it. The problem is this initializer:

Oj.default_options = { symbol_keys: true }

Propshaft uses standard JSON.parse when reading the manifest file, and therefore expects all keys (the asset names) to be string. This is turning them intro symbols. Just remove it and you will be fine.

@brenogazzola
Copy link
Collaborator

brenogazzola commented Mar 13, 2022

Sorry, I'll reopen this while I discuss with the others if we should support this option.

@brenogazzola brenogazzola reopened this Mar 13, 2022
@ghost
Copy link
Author

ghost commented Mar 13, 2022

@brenogazzola thank you so much - would have never guessed that to be the culprit. 😊

@brenogazzola
Copy link
Collaborator

No problem. Don’t forget to remove me from the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant