-
-
Notifications
You must be signed in to change notification settings - Fork 27k
fix: disable esModule on file-loader and url-loader to fix require() issues #9934
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you pass esModule: false
, does import image from './image.png'
keep working? If not, maybe we should leave ESModule as default and just mention the breaking change in the release description.
People using require
can change to require('./image.png').default
or import image from './image.png'
.
I have tested and both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and it works.
Since @ianschmitz has created the issue #8355, he may have some opinions on this. |
I'm not sure we'll want to move backwards to disable I don't believe we've ever recommended or suggested using |
If nothing else, a note should at least be added to the changelog about this. |
@ianschmitz Do you have any thought about re-considering this? This has been a very convenient way of working with images in react. Imagine a page/component that uses 10 images, and then we have to create import statements for each of these 👎 . As for developer experience, this ain't it 😞 . Inline require are much easier and clearer to use here. |
I don't understand the developer experience issue. The difference should only be if you were using require(), you'll have to add |
Oh no, I was just referring to when you said the docs don't recommend use of |
I was chatting to @ianschmitz about this and we've decided to close this for now as we don't recommend using Apologies that this was missed in the migration notes from v3 to v4, we understand that must have been frustrating for some people. |
In #8950,
There is a breaking change in
file-loader
andurl-loader
(esModule
enable by default). This causesrequire(..)
returns an object instead of a string, and it will break projects that upgrade fromv3
tov4
.This PR will disable
esModule
for those loaders to preserve the require behavior as inv3
Verify step
Both statements below should work.
I don't know if it is an intention to enable
esModule
in the loader or not. If so, we probably need to add it as a breaking break ofv4
as well.fix #9721, fix #9831