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

esModule file-loader compat #2613

Closed
eric-hemasystems opened this issue Jun 1, 2020 · 6 comments · Fixed by #2668
Closed

esModule file-loader compat #2613

eric-hemasystems opened this issue Jun 1, 2020 · 6 comments · Fixed by #2668

Comments

@eric-hemasystems
Copy link

I recently upgraded an app from webpacker 4 -> 5. When I did that my "fontawesome" icons went away. I found the font was not loading despite being in the static_assets_extensions. When I looked at the compiled CSS it looked like:

@font-face {
  font-family: 'FontAwesome';
  src: url([object Module]);
  src: url("[object Module]?#iefix&v=4.7.0") format("embedded-opentype"), url([object Module]) format("woff2"), url([object Module]) format("woff"), url([object Module]) format("truetype"), url("[object Module]#fontawesomeregular") 

I did a search and found a related issue on stack overflow that indicates adding esModule: false to the fileloader options:

https://stackoverflow.com/questions/57671995/webpack-4-gives-background-urlobject-module-as-bg-image

I looked at the file-loader package and it appears in v5 they made a breaking change documented as:

switch to ES modules by default (the option esModule is true by default)

Since the file-loader config is controlled by webpacker making that config change would not be easy to do. Instead I downgraded to version 4.3 of file-loader and things are now working fine.

Seems either webpacker needs to be updated to use this esModule: false option or some other change needs to be made so it is compat with the new way file-loader is doing things.

@jakeNiemiec
Copy link
Member

Are you using the sprite-loader from that SO question? How are you require'ing fontawesome? (CSS or JS)

@eric-hemasystems
Copy link
Author

Not that I know of and I don't see it in my yarn.lock file.

  • The dependencies line on my package.json is "font-awesome": "^4.7.0"
  • app/javascripts/packs/application.js has import 'font-awesome/scss/font-awesome.scss'.
  • config/webpacker.yml has extract_css: true
  • app/layouts/application.html.erb has <%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>

@hoppergee
Copy link

I met a similar issue with file-loader and found a solution here. It may be useful for you.

environment.loaders.get('file').use.find(item => item.loader === 'file-loader').options.esModule = false

@PascalPixel
Copy link

Same here, no special loaders, but scss files are outputting src: url([object Module]); since upgrading webpacker. The above comment provided the solution by disabling esModule in file-loader.

@brendon
Copy link

brendon commented Jul 21, 2020

I'm so glad I found this! Is this something that should be fixed in webpacker?

@aried3r
Copy link
Contributor

aried3r commented Aug 3, 2020

Hey! I saw this and #2668. I think a more specific solution would be not to set esModule to false for every file extension but at least for those that are fonts and images like in https://github.com/freezy/vpweb/pull/54/files.

WDYT?

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.

6 participants