histoire-dev / histoire

⚡ Fast and beautiful interactive component playgrounds, powered by Vite
https://histoire.dev
MIT License
3.1k stars 181 forks source link

Web Worker breaks the build #600

Open melishev opened 9 months ago

melishev commented 9 months ago

Describe the bug

In my code I use the heic2any package, this package executes my code in Web Worker. When I try to run the Histoire build, I get an error:

Error while collecting story /home/mm/lib/docs/Components/**.story.vue:
ReferenceError: Worker is not defined
    at /home/mm/lib/node_modules/heic2any/dist/heic2any.js:23:33
    at /home/mm/lib/node_modules/heic2any/dist/heic2any.js:11:26
    at /home/mm/lib/node_modules/heic2any/dist/heic2any.js:20:2
    at ViteNodeRunner.runModule (file:///home/mm/lib/node_modules/vite-node/dist/client.mjs:342:11)
    at ViteNodeRunner.directRequest (file:///home/mm/lib/node_modules/vite-node/dist/client.mjs:326:16)
    at async ViteNodeRunner.cachedRequest (file:///home/mm/lib/node_modules/vite-node/dist/client.mjs:189:14)
    at async ViteNodeRunner.dependencyRequest (file:///home/mm/lib/node_modules/vite-node/dist/client.mjs:223:12)
    at async /home/mm/lib/source/hooks/useAssetManager/index.ts:2:31
    at async ViteNodeRunner.runModule (file:///home/mm/lib/node_modules/vite-node/dist/client.mjs:342:5)
    at async ViteNodeRunner.directRequest (file:///home/mm/lib/node_modules/vite-node/dist/client.mjs:326:5)

Reproduction

  1. Create a new histoire project
  2. Install the heic2any package
  3. Create a story in which the heic2any package will be executed

System Info

Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 9.8.1 - ~/lib/node_modules/.bin/npm
npmPackages:
    @histoire/plugin-vue: ^0.17.1 => 0.17.1 
    @vitejs/plugin-vue: ^4.2.3 => 4.3.3 
    histoire: ^0.17.2 => 0.17.2 
    vite: ^4.4.5 => 4.4.9

Used Package Manager

npm

Validations

Akryum commented 9 months ago

Could you try putting the usage of it inside a component or wrap it using !isCollecting()?

senritsu commented 5 months ago

Same issue when using Histoire together with https://github.com/hairyf/vue3-pixi, (which depends on https://github.com/pixijs/pixijs, which exports a worker in some module). Workaround with isCollecting looks not possible here since the Worker is a module export.