cereschen / vite-plugin-svg-sprite-component

7 stars 4 forks source link

IE11 (I know!) throws Assignment to read-only error #2

Closed tanc closed 3 years ago

tanc commented 3 years ago

I'm transpiling this plugin as part of Vite legacy transpilation and IE11 is throwing the following error:

Unhandled promise rejection TypeError: Assignment to read-only properties is not allowed in strict mode

I've identified the issue as coming from this plugin by the time-honoured elimination method. I realise this may not be high on your priority list as IE11 doesn't support use with external SVGs but I'm hoping to use this plugin with a polyfill.

tanc commented 3 years ago

I suspect it is this line: https://github.com/cereschen/vite-plugin-svg-sprite-component/blob/main/src/index.ts#L146

style is considered read only in the spec and should not be set directly. Maybe something like:

svg.style.setProperty('display', 'none')

I just tested this by doing a find/replace on the compiled legacy output and confirmed that was the problem. The plugin works nicely and somehow is polyfilled to provide the svg use facility in IE11