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

Function statements require a function name on bundled app when using legacyPlugin #6546

Closed
7 tasks done
danielo515 opened this issue Jan 18, 2022 · 2 comments
Closed
7 tasks done

Comments

@danielo515
Copy link

danielo515 commented Jan 18, 2022

Describe the bug

This issue requires some very specific conditions to happen, but it is not the only problem related to legacyPlugin.
If I use legacyPlugin + firebase v9 I get an invalid production bundle. The bundle throws the following error:

Function statements require a function name

And the error points to a very long line on the vendor bundle, where there is a function that doesn't match such criteria.
It looks like the legacyPlugin is taking the wrong firebase build version which is not ready for browser operation? Not sure

On the reproduction just run yarn preview and you will face the error on the console.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ch1d1j?file=vite.config.ts

System Info

System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 8.57 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 6.14.11 - ~/mega/trabajo/GIT/pento-tech-challenge/delivery/front/node_modules/.bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 89.0
    Safari: 14.1.2
  npmPackages:
    @vitejs/plugin-legacy: ^1.4.4 => 1.6.4
    @vitejs/plugin-react: ^1.1.3 => 1.1.3
    @vitejs/plugin-react-refresh: ^1.3.5 => 1.3.6
    vite: 2 => 2.7.10

Used Package Manager

yarn

Logs

  vite:config bundled config file loaded in 483.20ms +0ms
  vite:config using resolved config: {
  vite:config   build: {
  vite:config     target: 'es2015',
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: '/home/projects/vitejs-vite-ch1d1j/build',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: 'es2015',
  vite:config     sourcemap: 'inline',
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   plugins: [
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:react-babel',
  vite:config     'vite:react-refresh',
  vite:config     'vite:react-jsx',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-script-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:legacy-env',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:client-inject',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined
  vite:config   },
  vite:config   resolve: { dedupe: [ 'react', 'react-dom' ], alias: [ [Object], [Object] ] },
  vite:config   optimizeDeps: {
  vite:config     include: [ 'react/jsx-dev-runtime' ],
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   },
  vite:config   define: { 'import.meta.env.LEGACY': false },
  vite:config   configFile: '/home/projects/vitejs-vite-ch1d1j/vite.config.ts',
  vite:config   configFileDependencies: [ 'vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     preview: {
  vite:config       port: undefined,
  vite:config       strictPort: undefined,
  vite:config       host: undefined,
  vite:config       https: undefined,
  vite:config       open: undefined
  vite:config     }
  vite:config   },
  vite:config   root: '/home/projects/vitejs-vite-ch1d1j',
  vite:config   base: '/',
  vite:config   publicDir: '/home/projects/vitejs-vite-ch1d1j/public',
  vite:config   cacheDir: '/home/projects/vitejs-vite-ch1d1j/node_modules/.vite',
  vite:config   command: 'serve',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) {},
  vite:config   createResolver: [Function: createResolver]
  vite:config } +6ms
  > Local: http://localhost:5000/
  > Network: use `--host` to expose

Validations

@danielo515
Copy link
Author

danielo515 commented Jan 18, 2022

This seems to be the minimum config required to trigger this problem:

export default defineConfig({
  build: {
    target: 'es2015',
    minify: 'esbuild',
    manifest: false,
    sourcemap: 'inline',
    outDir: 'build',
  },
  plugins: [
    react(),
    legacyPlugin({
      targets: [
        'Android > 39',
        'Chrome >= 60',
        'iOS >= 10.3',
        'Firefox >= 54',
        'Edge >= 15',
      ],
    }),
  ],
});

If you remove either the build options or the legacyPlugin the problem doesn't happen.

@sapphi-red
Copy link
Member

After updating Vite to v2.9.5 and plugin-legacy to 1.8.1 fixed this. (Maybe because minify was switched to terser?)
Closing as this is already fixed.

@github-actions github-actions bot locked and limited conversation to collaborators May 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants