-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Upgrade from v6 to v7 sends digested assets to outside packs folder #538
Comments
Further to the statements above, it appears (to my untrained eye) that content in any folder above the Edit: This statement appears true since |
Thanks for reporting. It looks like the crux of the issue is in this file shakapacker/package/rules/file.js Line 23 in 0829d5a
With your example, the resource filename ends up being something like Actually v6 behaviour seems to be incorrect also. I would have expected the static files to land in Spend a good while tracing this as couldn't reproduce in my toy repo. Ended up tracing this to https://github.com/chuttam/shakapacker-scss-test/blob/main/config/webpack/webpack.config.js#L34 - that context line. Without it, the behaviour I see is correct. Which does make sense as the resolutions will be done against cwd rather than the nested directory and having to go up a tree. If there's no concrete reason why you need the context declaration there, removing it is one way to go around this issue. The other, in the meantime is redefining the rule in your webpack config to change the behaviour of the generator here: shakapacker/package/rules/file.js Line 11 in 0829d5a
So it ends up with the key part being something like:
|
Related Webpack issue webpack/webpack#14392 |
Looking into it more, it will definitely be more involved than just stripping relative segments from the path. Say I have: And file that lives under Then shakapacker/package/rules/file.js Line 13 in 0829d5a
../assets/images/test_additional.svg
And land in And without context set it would land in So does need more thinking. As per linked Webpack issue it seems to be mainly due to behaviour difference between previous file-loader and new asset modules so would be helpful if Webpack itself provided something to support the use case here. Thinking that one way to go about it is to try and resolve paths against |
@tomdracz First off, thank you for the diligence you've put into your responses. It definitely makes my days of effort crafting the question feel worthwhile and not futile. My knee-jerk reaction would be to ideally remove the manual context declaration. Given this is an inherited project, I'd have to test the application extensively and get back to you whether this can be a successful resolution. I may also attempt custom logic to strip out ".." segments VERY specifically for the font library in question. Thanks for tracking the underlying webpack issue down, by the way. I'd never have found it. |
Thank you! Custom logic just for the fonts might be sensible. To pinpoint any other issues with context removal, I'd suggest to diff the manifest.json file generated after compilation with and without the context configured. That should allow you to see if anything apart from the fonts ends up declared differently, if not, then should be safe to remove. I'd expect this to only affect static file assets pulled from node_modules and additional paths outside the main source folder. Got a good grasp on the scenarios now so will try and cook up some test cases than I can validate and fixes with, but will take some time. Appreciate the report again, definitely something that we've not noticed around the Webpack change so at the very least I'll try and document this. |
Doc update merged. Keeping this issue open as still exploring potential fixes |
@tomdracz Just confirming here that I was able to get my application to run successfully despite explicitly removing the context path option. A few lookup adjustments had to be made elsewhere, but all easily manageable. Third-party assets as |
Great, thanks for the update @chuttam ! |
Note: Shakapacker v7.2.3 upgrade attempt from shakapacker v6.5.2 (currently working fine in production)
A discussion had previously been opened describing the same issue, but it was closed after discussion went into an irrelevant tangent around root cause, with no solutions offered.
Root Question
Why does running
/bin/shakapacker
with assets from npm modules createnode_modules
outsidepacks
in v7, but createsnode_modules
folder withinpacks
in v6?Expected behavior:
When running
bin/shakapacker
, some 3rd-party assets (.eot, .woff, .woff2 font assets fromfont-awesome
) are digested and placed in the following folder:This is the current, working behaviour with shakapacker v6.5.2. Browser access to
https://my.asset.host/packs/node_modules/@fortawesome/fontawesome-pro/webfonts/fa-brands-400-2ac0cbf0ae3aa5e15f77.eot
for example, resolves fine.These assets are imported via the following SCSS file and appear to be picked up fine by the loader, and generate the pack manifest.
Actual behavior:
After upgrade to shakapacker v7.2.3, these assets are digested to a
node_modules/
folder inpublic/
(i.e. outside the pack):The upgrade from shakapacker 6 to 7 is essentially the renaming of "webpacker" to "shakapacker". Here is a copy of the webpack config (identical to v6 version):
webpack.config.js
shakapacker.yml
The generated manifest entries for the font assets appear technically correct:
However, any attempt to access the file in question is met with a
404
from our application, and these assets render as missing.Small, reproducible repo: https://github.com/chuttam/shakapacker-scss-test
(run
bin/shakapacker
to see results inpublic/
andpublic/packs
)Setup environment:
The text was updated successfully, but these errors were encountered: