-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
Incompatibility with file-loader version 5 #367
Comments
#362 is a related issue. As far as I understood from @evilebottnawi 's explanation in this thread, webpack-contrib/file-loader#351, forcing file-loader to use commonjs modules instead of esmodules will increase the file size of the output. |
Exactly. Which is why I explain in the OP that this can be solved in a fairly simple manner by updating the regex there: https://github.com/smooth-code/svgr/blob/1915aee289fcbe29237dca1b94e8309b971549f3/packages/webpack/src/index.js#L34 |
Same problem. The workaround fix is: - const previousExport = exportMatches ? `export default ${exportMatches[1]}` : null;
+ const previousExport = exportMatches ? `export default ${exportMatches[1]}` :
+ source.toString('utf-8').startsWith('export') ? source : null; |
Will be fixed in v5. |
Hello,
Just to let you know, I have found a case where you have an incompatibility with file-loader version 5, than can easily be solved by a small modification on your side.
You enable loading SVGs both as react components and good old files with file-loader / url-loader. The thing is that in that case you expect the output of file-loader to be a commonJs type of export, hence the regular expression you have here: https://github.com/smooth-code/svgr/blob/1915aee289fcbe29237dca1b94e8309b971549f3/packages/webpack/src/index.js#L34
However the last version of file-loader (v5) now outputs by default an ESM type of export, which does not work with this regex anymore. So the webpack plugin thinks it's actually reading the SVG, and of course parsing that ESM export as an SVG fails.
The not so explicit error one gets when launching webpack is the following:
The good news is it can be solved without a change on your side, by setting file-loader to use old commonJs exports (https://github.com/webpack-contrib/file-loader#esmodule). But of course it would be nice if that was not required !
Thanks for this great library !
The text was updated successfully, but these errors were encountered: