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

Incorrect chunking when code has top-level await #10995

Closed
7 tasks done
productdevbook opened this issue Nov 19, 2022 · 7 comments
Closed
7 tasks done

Incorrect chunking when code has top-level await #10995

productdevbook opened this issue Nov 19, 2022 · 7 comments
Labels
bug: upstream Bug in a dependency of Vite

Comments

@productdevbook
Copy link

productdevbook commented Nov 19, 2022

Describe the bug

my library write and used with vite.
but vite build and preview mode reload refresh page 2-3 time empty page.

but dev mode working all.

Reproduction

https://github.com/productdevbook/vite-bug-vue

Steps to reproduce

pnpm install
pnpm build
pnpm preview

chrome debugger mode this problem. console.log dont see and working

image

System Info

System:
    OS: Linux 5.17 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11400 @ 2.60GHz
    Memory: 9.98 GB / 31.12 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.12.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
  Browsers:
    Chrome: 107.0.5304.110
  npmPackages:
    @vitejs/plugin-vue: ^3.2.0 => 3.2.0 
    vite: ^3.2.4 => 3.2.4

Used Package Manager

pnpm

Logs

Click to expand!
  vite:config bundled config file loaded in 39.51ms +0ms
  vite:esbuild init tsconfck (root: /home/productdevbook/Downloads/vite-bug/vite-bug-vue) +0ms
  vite:esbuild init tsconfck (root: /home/productdevbook/Downloads/vite-bug/vite-bug-vue) +0ms
  vite:esbuild init tsconfck (root: /home/productdevbook/Downloads/vite-bug/vite-bug-vue) +1ms
  vite:esbuild init tsconfck (root: /home/productdevbook/Downloads/vite-bug/vite-bug-vue) +0ms
  vite:esbuild init tsconfck end +1ms
  vite:esbuild init tsconfck end +0ms
  vite:esbuild init tsconfck end +0ms
  vite:esbuild init tsconfck end +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:ensure-watch',
  vite:config     'vite:build-metadata',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'vite:ensure-watch',
  vite:config     'vite:watch-package-data',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   build: {
  vite:config     target: 'esnext',
  vite:config     cssTarget: 'esnext',
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: false,
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  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     w: true,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true }
  vite:config   },
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     force: undefined,
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     external: [],
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   configFile: '/home/productdevbook/Downloads/vite-bug/vite-bug-vue/vite.config.ts',
  vite:config   configFileDependencies: [
  vite:config     '/home/productdevbook/Downloads/vite-bug/vite-bug-vue/vite.config.ts'
  vite:config   ],
  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     optimizeDeps: { force: undefined },
  vite:config     build: { watch: true, w: true }
  vite:config   },
  vite:config   root: '/home/productdevbook/Downloads/vite-bug/vite-bug-vue',
  vite:config   base: '/',
  vite:config   resolve: {
  vite:config     mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
  vite:config     browserField: true,
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   publicDir: '/home/productdevbook/Downloads/vite-bug/vite-bug-vue/public',
  vite:config   cacheDir: '/home/productdevbook/Downloads/vite-bug/vite-bug-vue/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  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     headers: undefined
  vite:config   },
  vite:config   env: {
  vite:config     VITE_USER_NODE_ENV: 'production',
  vite:config     BASE_URL: '/',
  vite:config     MODE: 'production',
  vite:config     DEV: false,
  vite:config     PROD: true
  vite:config   },
  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   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       'vite:ensure-watch',
  vite:config       'vite:build-metadata',
  vite:config       'vite:pre-alias',
  vite:config       'alias',
  vite:config       'vite:modulepreload-polyfill',
  vite:config       'vite:resolve',
  vite:config       'vite:html-inline-proxy',
  vite:config       'vite:css',
  vite:config       'vite:esbuild',
  vite:config       'vite:json',
  vite:config       'vite:wasm-helper',
  vite:config       'vite:worker',
  vite:config       'vite:asset',
  vite:config       'vite:wasm-fallback',
  vite:config       'vite:define',
  vite:config       'vite:css-post',
  vite:config       'vite:build-html',
  vite:config       'vite:worker-import-meta-url',
  vite:config       'vite:asset-import-meta-url',
  vite:config       'vite:force-systemjs-wrap-complete',
  vite:config       'vite:ensure-watch',
  vite:config       'vite:watch-package-data',
  vite:config       'commonjs',
  vite:config       'vite:data-uri',
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:build-import-analysis',
  vite:config       'vite:esbuild-transpile',
  vite:config       'vite:reporter',
  vite:config       'vite:load-fallback'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +7ms
vite v3.2.4 building for production...

watching for file changes...

build started...
✓ 815 modules transformed.
dist/assets/vue.5532db34.svg     0.48 KiB
dist/index.html                  0.44 KiB
dist/assets/index.dbc02544.js    1.29 KiB / gzip: 0.56 KiB
dist/assets/index.afd3776d.js    9.58 KiB / gzip: 2.72 KiB
dist/assets/index.36623d5e.js    8.88 KiB / gzip: 2.59 KiB
dist/assets/index.000adf7d.js    13.98 KiB / gzip: 4.19 KiB
dist/assets/index.4496d51b.css   1.57 KiB / gzip: 0.72 KiB
dist/assets/index.454739ca.js    8.61 KiB / gzip: 2.57 KiB
dist/assets/index.ebedfc73.js    9.28 KiB / gzip: 2.68 KiB
dist/assets/index.1ee6e682.js    446.36 KiB / gzip: 100.49 KiB
built in 1723ms.

Validations

@productdevbook productdevbook changed the title import default is emty data import default dont working Nov 19, 2022
@productdevbook productdevbook changed the title import default dont working import default dont working build and preview mode Nov 19, 2022
@productdevbook
Copy link
Author

some code local test working and vite dev working

image

@productdevbook
Copy link
Author

but vite build after dont see b

image

@luo3house
Copy link
Contributor

I guess the main module main.ts used an await keyword, it blocks the module preloading when there are circular import.

// main.ts
const locale = await loadDateFNSLocale({
    locale: 'tr-TR',
    storageKey: 'locale'
})
// ...
app.mount('#app')

Assume that main.ts begin to load a locale/tr-TR. However the module tr-TR also depends on a shared library, which bundled with main.ts together. Then occured a circular await import.

main.ts <- await import('tr-TR') <- import('main.ts') <- await import('tr-TR') <- ...

I import locale module asynchronously, then it worked.

// main.ts
async function initApp() {
  const locale = await loadDateFNSLocale({
      locale: 'tr-TR',
      storageKey: 'locale'
  })
  // ...
  app.mount('#app')
}
initApp() // load asynchronously

or

// main.ts
loadDateFNSLocale({
    locale: 'tr-TR',
    storageKey: 'locale'
}).then(locale => {
  // load as promise
  // ...
  app.mount('#app')
})

@productdevbook
Copy link
Author

productdevbook commented Nov 19, 2022

Thank you, Is this a permanent solution ?

@sapphi-red
Copy link
Member

This seems to be an upstream issue (rollup/rollup#4708).
https://stackblitz.com/edit/rollup-template-v2cra2?file=src%2Fmain.js

The current workaround is to avoid TLA as @luo3house said (thanks!).

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite and removed pending triage labels Nov 20, 2022
@sapphi-red sapphi-red changed the title import default dont working build and preview mode Incorrect chunking when code has top-level await Feb 19, 2023
@bluwy
Copy link
Member

bluwy commented Oct 16, 2023

Going to close this as there's not much we can do. The linked rollup issue has some findings I made while trying to fix it upstream, but it was harder than expected.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2023
@productdevbook
Copy link
Author

Failure to resolve the issue indicates why the issue should be closed. I think it should stay open because it's a bug.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet
Development

No branches or pull requests

4 participants