Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy plugin produces broken build with renderModernChunks=false & polyfills=false #14324

Closed
7 tasks done
k-yle opened this issue Sep 8, 2023 · 1 comment · Fixed by #14346
Closed
7 tasks done

Legacy plugin produces broken build with renderModernChunks=false & polyfills=false #14324

k-yle opened this issue Sep 8, 2023 · 1 comment · Fixed by #14346
Labels
contribution welcome p3-minor-bug An edge case that only affects very specific usage (priority) plugin: legacy

Comments

@k-yle
Copy link
Contributor

k-yle commented Sep 8, 2023

Describe the bug

plugins: [
      react(),
      legacy({
        renderModernChunks: false,
        polyfills: false,
      }),
    ],

When using the legacy plugin with these two options, the compiled output is broken because SystemJS is not injected.

Example - note how dist/index.html refers to System, but SystemJS is not imported.

I'm happy to make a PR to fix this, we are currently bypassing this bug by adding this snippet to packages/plugin-legacy/src/index.ts:594:

      // 6. Inject SystemJS
      if (!genModern && !options.polyfills) {
        const systemJsRuntime = fs
          .readFileSync(require.resolve('systemjs/dist/s.min.js'), 'utf8')
          .split("//# sourceMappingURL")[0]
        html = html.replace(/<\/head>/g, `<script>${systemJsRuntime}</script></head>`)
      }

Reproduction

https://github.com/k-yle/vite-legacy-broken-build

Steps to reproduce

  • clone the example repo
  • npm i
  • npm run build
  • try to open index.html - note how SystemJS is missing.

System Info

System:
    OS: Windows 10 10.0.*****
    CPU: (*) *******
    Memory: ***********
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.****.****.*), Chromium (116.0.****.*)
    Internet Explorer: 11.0.****.*
  npmPackages:
    @vitejs/plugin-legacy: ^4.1.1 => 4.1.1 
    @vitejs/plugin-react: ^4.0.4 => 4.0.4 
    vite: ^4.4.9 => 4.4.9

Used Package Manager

npm

Logs

Click to expand!
warning package.json: No license field
$ vite build
vite v4.4.9 building for production...
✓ 32 modules transformed.
dist/index.html                             0.42 kB │ gzip:  0.26 kB
dist/assets/file2-legacy-4d4e3654.js        0.09 kB │ gzip:  0.10 kB
dist/assets/polyfills-legacy-a26809ba.js   91.53 kB │ gzip: 36.33 kB
dist/assets/index-legacy-c4fde549.js      142.03 kB │ gzip: 45.52 kB
✓ built in 6.45s
Done in 7.28s.

Validations

@sapphi-red sapphi-red added contribution welcome plugin: legacy p3-minor-bug An edge case that only affects very specific usage (priority) labels Sep 10, 2023
@sapphi-red
Copy link
Member

SystemJS is included in the polyfill chunk. But this condition is skipping the polyfill chunk generation.

if (legacyPolyfills.size) {

I guess simply removing this condition would fix it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution welcome p3-minor-bug An edge case that only affects very specific usage (priority) plugin: legacy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants