Skip to content

Worker is built in legacy mode with the {type: "module"} option #6761

@KubesDavid

Description

@KubesDavid

Describe the bug

After running vite build, Worker is built in legacy mode with the {type: "module"} option, which is undesirable in this case and results in the application breaking in older browser versions.

vite.config.ts

import vue from '@vitejs/plugin-vue';
import legacy from '@vitejs/plugin-legacy';
import { resolve } from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [vue(), legacy()],
  build: {
    reportCompressedSize: false,
  },
  worker: {
    format: 'iife',  // 'es' produces the same output
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
  },
});

index-legacy.057ce815.js

return new Worker("/assets/tv.worker.b73a6f8e.js", {type: "module"})

Reproduction

https://stackblitz.com/edit/node-kfimtt

System Info

System:
    OS: macOS 12.2
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 1.82 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.4.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.4.0 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 98.1.35.100
    Chrome: 60.0.3112.113
    Safari: 15.3
  npmPackages:
    @vitejs/plugin-legacy: ^1.6.4 => 1.6.4 
    @vitejs/plugin-vue: ^2.1.0 => 2.1.0 
    vite: ^2.8.0-beta.5 => 2.8.0-beta.5

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions