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

Missing CSS via dynamic import in node_modules package after build #6823

Closed
7 tasks done
FL3NKEY opened this issue Feb 9, 2022 · 1 comment · Fixed by #7969
Closed
7 tasks done

Missing CSS via dynamic import in node_modules package after build #6823

FL3NKEY opened this issue Feb 9, 2022 · 1 comment · Fixed by #7969

Comments

@FL3NKEY
Copy link

FL3NKEY commented Feb 9, 2022

Describe the bug

For example we have node package with some Vue components that have CSS.

  • node-package/
    • components/AsyncA.vue
    • components/AsyncB.vue
    • components/Root.vue

Root.vue imports AsyncA.vue and AsyncB.vue components via dynamic import like this:

<template>
    <div class="root">
        <async-a></async-a>
        <async-b></async-b>
    </div>
</template>

<script>
import { defineAsyncComponent } from 'vue';

const AsyncA = defineAsyncComponent(() => import('./AsyncA.vue'));
const AsyncB = defineAsyncComponent(() => import('./AsyncB.vue'));

export default {
    components: {
        AsyncA,
        AsyncB
    }
}
</script>

We have project with installed package via npm and import node-package/components/Root.vue in our App.vue.

<template>
    <div>
        <root></root>
    </div>
</template>

<script>
import Root from 'node-package/components/Root.vue'; // import from node_modules

export default {
    components: {
        Root
    }
}
</script>

If we run vite in development mode (vite dev), we'll see css of all components (AsyncA.vue, AsyncB.vue and Root.vue).

Снимок экрана 2022-02-09 в 14 42 50

Ok, but if we run vite build and vite preview, we don't see css of AsyncA.vue and AsyncB.vue components.

Снимок экрана 2022-02-09 в 14 44 00

But in console we have all css chunks.

vite v2.8.0 building for production...
✓ 16 modules transformed.
dist/index.html                   0.48 KiB
dist/assets/AsyncB.be6acdee.css   0.05 KiB / gzip: 0.07 KiB
dist/assets/index.2abbd1e7.js     0.93 KiB / gzip: 0.54 KiB
dist/assets/AsyncA.86417d28.js    0.17 KiB / gzip: 0.17 KiB
dist/assets/vendor.fefc9991.css   0.04 KiB / gzip: 0.06 KiB
dist/assets/AsyncA.d065db1c.css   0.06 KiB / gzip: 0.07 KiB
dist/assets/AsyncB.3238aebf.js    0.17 KiB / gzip: 0.17 KiB
dist/assets/vendor.4d95b76a.js    48.61 KiB / gzip: 19.65 KiB

(!!!) If we consider this case without participation node_modules (move node package directory in project root), then it will works as it should.

Thanks!

Reproduction

https://github.com/FL3NKEY/reproduce-vite-async-css-bug

System Info

System:
    OS: macOS 11.2.3
    CPU: (8) arm64 Apple M1
    Memory: 73.53 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.0.0 - /usr/local/bin/node
    npm: 7.10.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Firefox: 97.0
    Safari: 14.0.3
  npmPackages:
    @vitejs/plugin-vue: ^2.2.0 => 2.2.0 
    vite: ^2.8.0 => 2.8.0

Used Package Manager

npm

Logs

> vite build "--debug"

  vite:config bundled config file loaded in 47.31ms +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-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  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: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  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   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: '/Users/fl3nkey/DEV/vite-test-async-css-bug/reproduce/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: {}
  vite:config   },
  vite:config   root: '/Users/fl3nkey/DEV/vite-test-async-css-bug/reproduce',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/Users/fl3nkey/DEV/vite-test-async-css-bug/reproduce/public',
  vite:config   cacheDir: '/Users/fl3nkey/DEV/vite-test-async-css-bug/reproduce/node_modules/.vite',
  vite:config   command: 'build',
  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   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: { 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   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object]
  vite:config     ],
  vite:config     rollupOptions: {}
  vite:config   }
  vite:config } +3ms
vite v2.8.0 building for production...
✓ 16 modules transformed.
dist/index.html                   0.48 KiB
dist/assets/AsyncB.3238aebf.js    0.17 KiB / gzip: 0.17 KiB
dist/assets/AsyncA.86417d28.js    0.17 KiB / gzip: 0.17 KiB
dist/assets/AsyncA.d065db1c.css   0.06 KiB / gzip: 0.07 KiB
dist/assets/vendor.fefc9991.css   0.04 KiB / gzip: 0.06 KiB
dist/assets/AsyncB.be6acdee.css   0.05 KiB / gzip: 0.07 KiB
dist/assets/index.2abbd1e7.js     0.93 KiB / gzip: 0.54 KiB
dist/assets/vendor.4d95b76a.js    48.61 KiB / gzip: 19.65 KiB

Validations

@FL3NKEY FL3NKEY changed the title CSS dynamic import in node_modules package not applied with build Missing CSS via dynamic import in node_modules package after build Feb 9, 2022
FL3NKEY added a commit to FL3NKEY/vite that referenced this issue Feb 9, 2022
FL3NKEY added a commit to FL3NKEY/vite that referenced this issue Feb 9, 2022
@FL3NKEY
Copy link
Author

FL3NKEY commented Feb 9, 2022

Fix #6829

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants