question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite build doesn‘t work with virtual modules imported from WebWorker

See original GitHub issue

Describe the bug

Only by adding this plugin to rollup as well will it pass compilation.

import plugin from './plugin.js';

export default {
  plugins: [plugin()],
  build: {
    rollupOptions: {
      // plugins: [plugin()],
    },
  },
};

More details can be found in the reproduction. trust me, it is a minimal and will not waste too much of your time.

Reproduction

https://stackblitz.com/edit/vitejs-vite-mojc3s?file=vite.config.js

System Info

n/a

Used Package Manager

pnpm

Logs

No response

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
zhmushancommented, Jun 13, 2022

For consistency, we should also keep the root-level plugin from taking effect on worker during the dev phase. Or print a warning message.

1reaction
sapphi-redcommented, Jun 9, 2022

Changing the config like below will fix this.

import plugin from './plugin.js';

export default {
  plugins: [plugin()],
  worker: {
    plugins: [plugin()]
  }
};

I’m not sure why worker.plugins exists separately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features | Vite (main branch)
Vite will detect such bare module imports in all served source files and perform the following: Pre-bundle them to improve page loading speed...
Read more >
A deep-dive on Vite featuring Evan You (JS Party #212)
Amal and Nick load up on coffee for a not-so-vite (lame joke!) ... for example when you import Lodash - so Lodash has...
Read more >
Bundling Extensions - Visual Studio Code
When VS Code is running in the browser, it can only load one file for your ... look for `browser` entry point in...
Read more >
Output - webpack
The format of chunks (formats included by default are 'array-push' (web/WebWorker), 'commonjs' (node.js), 'module' (ESM), but others might be added by plugins).
Read more >
Recommended - SlideShare
Virtual Modules Convention Virtual. ted char in import URLs so we have to replace them during import analysis. A. Modify Vite config before ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found