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

Failed to compress svg's #15

Open
Digital-Coder opened this issue Mar 31, 2022 · 6 comments
Open

Failed to compress svg's #15

Digital-Coder opened this issue Mar 31, 2022 · 6 comments

Comments

@Digital-Coder
Copy link

I got this error while trying this plugin. Any idea how to exclude svg's ? I tried : compress({ exclude: ["*.svg"] })

✓ 560 modules transformed.
[vite:compress] setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.
file: F:/GitHub/senf/apps/senf-client/src/images/svgIcons/plus.svg
error during build:
Error: setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook. at error (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:198:30)
at throwPluginError (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:21847:12)
at Object.error (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:22570:20)
at Object.error (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:22024:42)
at Object.setAssetSource (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:22043:33)
at Object.transform (F:\GitHub\senf\apps\senf-client\node_modules\vite-plugin-compress\dist\plugin.js:107:34)
at async transform (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:21994:16)
at async ModuleLoader.addModuleSource (F:\GitHub\senf\apps\senf-client\node_modules\rollup\dist\shared\rollup.js:22220:30)

source code looks like this:
import Plus from "../../../images/svgIcons/plus.svg";
<img src={Plus} width="25" alt="AddIcon" />

@aleclarson
Copy link
Contributor

Fixed in v2.1.1

@aleclarson
Copy link
Contributor

Well, the exclude option should work as intended, at least.

I haven't investigated the setAssetSource error yet.

@aleclarson aleclarson reopened this Mar 31, 2022
@Digital-Coder
Copy link
Author

Well, the exclude option should work as intended, at least.

I haven't investigated the setAssetSource error yet.

I am not even sure if I used glob pattern correctly for exclude option, but after failed tries, I just moved to another vite plugin which does not compress png's and svg's and that one seems to be working. But let me know if you find any fixes

@YuJianghao
Copy link

YuJianghao commented Apr 11, 2022

Well, the exclude option should work as intended, at least.
I haven't investigated the setAssetSource error yet.

I am not even sure if I used glob pattern correctly for exclude option, but after failed tries, I just moved to another vite plugin which does not compress png's and svg's and that one seems to be working. But let me know if you find any fixes

compress({ exclude: ["**.svg"] }), works for me.

*.svg only match foo.svg not foo/bar.svg. **.svg do that. globs special-character--double-star


Same setAssetSource error for [email protected] and [email protected]:

[vite:compress] setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.

@Digital-Coder
Copy link
Author

thanks for explanation !

@andreacfromtheapp
Copy link

hi :)

I also have the same error when running a build. However, I do want svg compression.

here's the error:

vite v2.9.8 building for production...
transforming (1) index.html Running elm make /Users/gacallea/Projects and Ideas/Sites/anerandros.info/src/elm/Main.elm --output /var/folders/f2/zz4hj6h97sq264l9fpxrgh7h0000gn/T/2022414-35553-m4886d.vgfmi.js --optimize
Success!     

    Main ───> /var/folders/f2/zz4hj6h97sq264l9fpxrgh7h0000gn/T/2022414-35553-m4886d.vgfmi.js


✓ 5 modules transformed.
[vite:compress] setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.
file: /Users/gacallea/Projects and Ideas/Sites/anerandros.info/src/img/covers/eos1.svg
error during build:
Error: setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.
    at error (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:198:30)
    at throwPluginError (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:21902:12)
    at Object.error (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:22625:20)
    at Object.error (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:22079:42)
    at Object.setAssetSource (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:22098:33)
    at Object.transform (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/vite-plugin-compress/dist/plugin.js:107:34)
    at async transform (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:22049:16)
    at async ModuleLoader.addModuleSource (/Users/gacallea/Projects and Ideas/Sites/anerandros.info/node_modules/rollup/dist/shared/rollup.js:22275:30)

the repo is public: https://github.com/gacallea/anerandros.info/

happy to provide more info and setup if needed :)

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

No branches or pull requests

4 participants