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.

build --watch does to output html or css when @vitejs/plugin-legacy is used

See original GitHub issue

Describe the bug

Vite does not output html or css when the @vitejs/plugin-legacy plugin is used

Possibly related to #3279 but that issue was closed

Reproduction

https://stackblitz.com/edit/vite-c4bxea?devtoolsheight=33

Reproducible by running vite build --watch

System Info

❯ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
success Install finished in 1.067s


  System:
    OS: Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: Unknown - /bin/jsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @vitejs/plugin-legacy: ^1.6.4 => 1.6.4 
    vite: ^2.6.0 => 2.7.2

Used Package Manager

npm

Logs

❯ vite build --watch --debug
  vite:config bundled config file loaded in 561.00ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'alias',
  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-config',
  vite:config     'vite:legacy-generate-polyfill-chunk',
  vite:config     'vite:legacy-env',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:legacy-post-process',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: '/home/projects/vite-c4bxea/dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: 'chrome61',
  vite:config     sourcemap: true,
  vite:config     rollupOptions: { input: '/home/projects/vite-c4bxea/index.html', output: [Array] },
  vite:config     minify: 'terser',
  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: true,
  vite:config     brotliSize: true,
  vite:config     w: true,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   define: { 'import.meta.env.LEGACY': '__VITE_IS_LEGACY__' },
  vite:config   configFile: '/home/projects/vite-c4bxea/vite.config.js',
  vite:config   configFileDependencies: [ 'vite.config.js' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: { watch: true, w: true }
  vite:config   },
  vite:config   root: '/home/projects/vite-c4bxea',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/home/projects/vite-c4bxea/public',
  vite:config   cacheDir: '/home/projects/vite-c4bxea/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   server: { fs: { strict: true, allow: [Array], deny: [Array] } },
  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   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) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   }
  vite:config } +8ms
vite v2.7.2 building for production...

watching for file changes...

build started...
✓ 4 modules transformed.
rendering chunks (1)...[@vitejs/plugin-legacy] legacy polyfills: Set(5) {
  'core-js/modules/es.promise',
  'core-js/modules/es.array.iterator',
  'core-js/modules/es.array.iterator.js',
  'core-js/modules/web.dom-collections.iterator.js',
  'core-js/modules/es.promise.js'
}
  vite:config using resolved config: {
  vite:config   root: '/home/projects/vite-c4bxea/node_modules/@vitejs/plugin-legacy',
  vite:config   configFile: undefined,
  vite:config   logLevel: 'error',
  vite:config   plugins: [
  vite:config     'alias',
  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-polyfills',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   build: {
  vite:config     target: false,
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: '/home/projects/vite-c4bxea/node_modules/@vitejs/plugin-legacy/dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: false,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { input: [Object], output: [Object] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     write: false,
  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   configFileDependencies: [],
  vite:config   inlineConfig: {
  vite:config     root: '/home/projects/vite-c4bxea/node_modules/@vitejs/plugin-legacy',
  vite:config     configFile: false,
  vite:config     logLevel: 'error',
  vite:config     plugins: [ [Object] ],
  vite:config     build: {
  vite:config       write: false,
  vite:config       target: false,
  vite:config       minify: 'terser',
  vite:config       assetsDir: 'assets',
  vite:config       rollupOptions: [Object]
  vite:config     }
  vite:config   },
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/home/projects/vite-c4bxea/node_modules/@vitejs/plugin-legacy/public',
  vite:config   cacheDir: '/home/projects/vite-c4bxea/node_modules/@vitejs/plugin-legacy/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   server: { fs: { strict: true, allow: [Array], deny: [Array] } },
  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   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) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   }
  vite:config } +2s
rendering chunks (2)...[vite:build-html] No corresponding legacy polyfill chunk found for /home/projects/vite-c4bxea/index.html
dist/assets/index-legacy.5c4c0183.js       0.49 KiB / gzip: 0.36 KiB
dist/assets/index-legacy.5c4c0183.js.map   0.37 KiB
dist/assets/polyfills-legacy.ff863e63.js   30.00 KiB / gzip: 12.50 KiB

Validations

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

4reactions
morelearn1990commented, Mar 31, 2022

I printed some logs that showed that some hook functions were executed in the wrong order when using watch。 截屏2022-03-31 23 38 08

plugin vite:legacy-post-process hook transformIndexHtml execution time has been advanced.

How should i resolve this?

Reproduction:

https://stackblitz.com/edit/vitejs-vite-4znqdj?file=vite.config.ts&terminal=build-w

0reactions
VaJoycommented, Dec 12, 2022

I had the same problem.

I have a mistake here: [vite:build-html] No corresponding legacy polyfill chunk found for /home/projects/github-kyokdx-u2bdcf/app2/index.html

my project use @originjs/vite-plugin-federation and @vitejs/plugin-legacy both. Remove @originjs/vite-plugin-federation,the mistake will gone.

I try to changed the filename in the federation configuration to “remoteEntry-legacy.js”,the mistake also will gone,but I not sure @vitejs/plugin-legacy work successfull.

WechatIMG53

Reproduction: https://stackblitz.com/edit/github-kyokdx-u2bdcf?file=readme.md,app2%2Fvite.config.js,package.json

cd app2
yarn build

I’ve got the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Options
Returning a relative path to the hostId for hostType === 'js' is allowed, in which case new URL(dep, import.meta.url) is used to get...
Read more >
Vite plugin for Craft CMS | Vite Plugin Documentation
Vite is a bridge between Craft CMS/Twig and the next generation frontend build tool Vite.js. Vite allows for Hot Module Replacement (HMR) of...
Read more >
Comparing the New Generation of Build Tools
We'll compare the output of each build step later. ... Then we can use the esbuild Javascript API to start as server and...
Read more >
vite build
To support legacy browsers, Vite offers @vite_js/plugin-legacy. Vite can also be used to build libraries and watch mode. You can learn more ...
Read more >
Beginner's luck #4: the Vite edition
If you prefer just to add Vite to your own Eleventy repo, you can do the same, ... npm i -D @vitejs/plugin-legacy browser-sync...
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