vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
69.04k stars 6.24k forks source link

"TypeError: undefined is not a function at System.register.execute" in chrome 39 #17405

Closed oyster0118 closed 5 months ago

oyster0118 commented 5 months ago

Describe the bug

"TypeError: undefined is not a function
    at System.register.execute (https://XXX/assets/index-legacy-4ace9b4e.js:28:31225)
    at n (https://XXX/assets/polyfills-legacy-05ebab4a.js:1:57039)
    at v (https://XXX/assets/polyfills-legacy-05ebab4a.js:1:57413)
    at https://XXX/assets/polyfills-legacy-05ebab4a.js:1:56952
    at nl (https://XXX/assets/polyfills-legacy-05ebab4a.js:1:24256)
    at https://XXX/assets/polyfills-legacy-05ebab4a.js:1:24487
    at MutationObserver.Jf (https://XXX/assets/polyfills-legacy-05ebab4a.js:1:22200)"

vite.config.ts

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
  base:'/xx',
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
    legacy({
      targets: ['defaults', 'android >= 4.4', 'chrome >= 39'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      renderLegacyChunks: true,
      polyfills:[
        'es.symbol',
        'es.array.filter',
        'es.promise',
        'es/reflect',
        'es.promise.finally',
        'es/map',
        'es/set',
        'es.array.for-each',
        'es.object.define-properties',
        'es.object.define-property',
        'es.object.get-own-property-descriptor',
        'es.object.get-own-property-descriptors',
        'es.object.keys',
        'es.object.to-string',
        'web.dom-collections.for-each',
        'esnext.global-this',
        'esnext.string.match-all'
      ]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 8080,
    proxy: {
      '/xxxt': {
        target: 'https://XXX.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/XX/, 'XX')
      }
    },
  }
})

Reproduction

https://stackblitz.com/edit/vitejs-vite-fdnmkt?file=vite.config.ts,package.json,index.html&terminal=dev

Steps to reproduce

No response

System Info

System:
    OS: Windows 10 10.0.17763
    CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
    Memory: 1.96 GB / 7.44 GB
  Binaries:
    Node: 18.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - ~\AppData\Roaming\npm\npm.CMD
    pnpm: 7.25.0 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Chrome: 125.0.6422.141(39.0.0.0)
    Internet Explorer: 11.0.17763.1
  npmPackages:
    @vitejs/plugin-legacy: ^4.1.1 => 4.1.1
    @vitejs/plugin-vue: ^4.4.0 => 4.4.0
    vite: ^4.4.11 => 4.5.0

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 5 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

bluwy commented 5 months ago

The repro given doesn't match the bug and setup you're describing. I can't replicate it locally. Can you update with a new repro link?

I'd also suggest minimizing the Vite plugins used and dependencies to narrow down what's causing it. From the error, it seems like System.register.execute is called before System.register is initialized by systemjs.

github-actions[bot] commented 5 months ago

Hello @oyster0118. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

oyster0118 commented 5 months ago

The repro given doesn't match the bug and setup you're describing. I can't replicate it locally. Can you update with a new repro link?

I'd also suggest minimizing the Vite plugins used and dependencies to narrow down what's causing it. From the error, it seems like System.register.execute is called before System.register is initialized by systemjs.

I just updated the link to reproduce the issue. In addition, I have a question: can the Vue3 application built by Vite be compatible with Chrome version 39?

sapphi-red commented 5 months ago

The error is happening because you didn't add the polyfill for Object.assign. If you add es.object.assign to polyfills, the undefined is not a function error disappears. But a different error (ReferenceError: Proxy is not defined) would be shown.

This is because Vue 3 doesn't support Chrome 39. https://vuejs.org/about/faq.html#what-browsers-does-vue-support

Closing as it's not a bug in Vite nor plugin-legacy.