Replies: 1 comment
-
I’ve confirmed that if I simply mkdir -p node_modules/.vite/assets
cp node_modules/@allmaps/render/dist/assets/* node_modules/.vite/assets/ … before I run the Vite dev server, everything works as expected. And, even better, the production build works as-is. So, this only seems to be a problem with the dev server, and is easily fixed by manually copying the worker script into |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am creating a Vite app which depends on a library (
@allmaps/render
) that uses a Web Worker.Allmaps also uses Vite to build their library, but there seems to be something wrong with the Vite bundling of the worker script causing it not to work—this is what I am trying to troubleshoot.
The TS source of the library initializes the Web Worker like this:
In the transpiled JS code of my Vite app I can see that this becomes:
… which is promising because in the
@allmaps/render
npm package there isdist/assets/fetch-and-get-image-data-BXcOBitk.js
.But Vite does not seem to include this worker script in my app bundle; there is no
node_modules/.vite/assets
dir. When I try to curlhttp://localhost:5173/node_modules/.vite/assets/fetch-and-get-image-data-BXcOBitk.js
I get backindex.html
(I guess as a fallback?), not the worker script. This is obviously causing the worker to fail (Uncaught SyntaxError: Unexpected token '<' (at fetch-and-get-image-data-BXcOBitk.js:1:1)
).Is this an Allmaps package publishing issue, or a Vite usage issue on my part? How can Vite be forced to include the worker script as an asset in the bundle?
Beta Was this translation helpful? Give feedback.
All reactions