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

Vite server 500 crash when using `VitePluginHelper.asset` with concatenated string

Open Erudition opened this issue 1 year ago • 4 comments

When I go to add VitePluginHelper.asset to my svg path strings in Elm, the server no longer works, and vite crashes with:

TypeError: Invalid value used in weak set
    at WeakSet.add (<anonymous>)
    at output (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:12529:30)
    at Object.error (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:12571:13)
    at logError (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:42888:26)
    at viteErrorMiddleware (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:42902:9)
    at call (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:48900:7)
    at next (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:48848:5)
    at call (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:48913:3)
    at next (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:48848:5)
    at call (file:///home/adroit/Projects/Minder/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-79892de8.js:48913:3)

But as soon as I take it out and leave it as a plain string, it works fine again.

Erudition avatar Apr 05 '23 06:04 Erudition

Edit: just realized this is due to: That string should be just a string without any concatenation. That seems to even apply to a single variable, no concatenation... so what it's really asking for is a string literal. I'm definitely going to need concatenation though.

but when I put in a full string url the problem does indeed go away... How can we accomplish this?

Erudition avatar Apr 05 '23 06:04 Erudition

Thanks for reporting! Can you provide a reproducible repo?

hmsk avatar Apr 26 '23 04:04 hmsk

Hi hmsk, I'm not able to start another vite project at the moment, but above I identified the issue as resulting from the lack of string concatenation support. If anyone else runs into this cryptic error, make sure you're only using full string literals to specify your asset paths.

I left the issue open in case anyone knows how we can get concatenation working, which is important in Elm for reusable functions -- e.g. if I have a button fn that sets the button icon based on its inputs, you may want to pass in something like "airplane" to the reusable function to specify the icon -- not env-specific/path/to/all/icons/airplane.svg. If we still need to specify somewhere all the icons we'll ever use, as Vite seems to depend on, that's fine, and doesn't necessarily rule out concatenation.

Erudition avatar May 04 '23 16:05 Erudition

Thanks for giving the additional detail! I don't know if we can make concatenation possible technically, but at least wanna try to avoid the crash and give a proper guide/warning.

hmsk avatar May 05 '23 01:05 hmsk