vite-plugin-compress icon indicating copy to clipboard operation
vite-plugin-compress copied to clipboard

Failed to compress svg's

Open Digital-Coder opened this issue 2 years ago • 6 comments

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" />

Digital-Coder avatar Mar 31 '22 10:03 Digital-Coder

Fixed in v2.1.1

aleclarson avatar Mar 31 '22 16:03 aleclarson

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

I haven't investigated the setAssetSource error yet.

aleclarson avatar Mar 31 '22 16:03 aleclarson

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

Digital-Coder avatar Mar 31 '22 19:03 Digital-Coder

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.

YuJianghao avatar Apr 11 '22 15:04 YuJianghao

thanks for explanation !

Digital-Coder avatar Apr 11 '22 16:04 Digital-Coder

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 :)

andreacfromtheapp avatar May 14 '22 10:05 andreacfromtheapp