fix: disable esModule on file-loader and url-loader to fix require() issues#9934
fix: disable esModule on file-loader and url-loader to fix require() issues#9934n3tr wants to merge 1 commit intofacebook:masterfrom
Conversation
There was a problem hiding this comment.
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 |
|
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-loaderandurl-loader(esModuleenable by default). This causesrequire(..)returns an object instead of a string, and it will break projects that upgrade fromv3tov4.This PR will disable
esModulefor those loaders to preserve the require behavior as inv3Verify step
Both statements below should work.
I don't know if it is an intention to enable
esModulein the loader or not. If so, we probably need to add it as a breaking break ofv4as well.fix #9721, fix #9831