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

Multiline comment in :global declaration in Sass file that is a CSS module throws minification warning #8480

Closed
7 tasks done
reintroducing opened this issue Jun 6, 2022 · 4 comments
Labels
bug: upstream Bug in a dependency of Vite feat: css

Comments

@reintroducing
Copy link

Describe the bug

When working with CSS modules in Sass files and including multi-line comments inside of a :global declaration, the production build shows a warning.

Given the following code:

:global {
  /*
   * Add the correct display in all browsers.
   */
  summary {
    display: list-item;
  }
}

When running npm run build it outputs the following CSS:

{}summary{display:list-item}

This shows the following warning during the build:

vite v2.9.9 building for production...
✓ 31 modules transformed.
warnings when minifying css:
▲ [WARNING] Unexpected "{"

    <stdin>:1:1:
      1 │  {
        ╵  ^

Removing the multi-line comment results in a proper build output with no warnings.

Reproduction

https://github.com/reintroducing/vite-css-module-comment-bug

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 82.06 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Firefox: 97.0.1
    Safari: 15.4
  npmPackages:
    @vitejs/plugin-react: ^1.3.0 => 1.3.2
    vite: ^2.9.9 => 2.9.9

Used Package Manager

npm

Logs

> vite build --debug

  vite:config bundled config file loaded in 99.63ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  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-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:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:watch-package-data',
  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   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   configFile: '/Users/mprzybylski/Desktop/vite-css-module-comment-bug/vite.config.js',
  vite:config   configFileDependencies: [
  vite:config     '/Users/mprzybylski/Desktop/vite-css-module-comment-bug/vite.config.js'
  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     build: {}
  vite:config   },
  vite:config   root: '/Users/mprzybylski/Desktop/vite-css-module-comment-bug',
  vite:config   base: '/',
  vite:config   publicDir: '/Users/mprzybylski/Desktop/vite-css-module-comment-bug/public',
  vite:config   cacheDir: '/Users/mprzybylski/Desktop/vite-css-module-comment-bug/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isWorker: false,
  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   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       [Object]
  vite:config     ],
  vite:config     rollupOptions: {}
  vite:config   }
  vite:config } +3ms
vite v2.9.9 building for production...
✓ 31 modules transformed.
warnings when minifying css:
▲ [WARNING] Unexpected "{"

    <stdin>:1:1:
      1 │  {
        ╵  ^


dist/index.html                  0.44 KiB
dist/assets/index.fe5fb74e.css   0.31 KiB / gzip: 0.24 KiB
dist/assets/index.26a25dd7.js    139.63 KiB / gzip: 44.76 KiB

Validations

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite feat: css and removed pending triage labels Jun 7, 2022
@sapphi-red
Copy link
Member

sass compiles

:global {
  /*
    * Add the correct display in all browsers.
    */
  summary {
    display: list-item;
  }
}

into

:global {
  /*
    * Add the correct display in all browsers.
    */
}
:global summary {
  display: list-item;
}

This is correct I think.

Then postcss + postcss-modules compiles it to

 {
  /*
    * Add the correct display in all browsers.
    */
}
summary {
  display: list-item;
}

This part does not seems to be working.

https://stackblitz.com/edit/node-2pmbyx?file=sass.js,postcss.js

@reintroducing
Copy link
Author

@sapphi-red great find! does this need to be opened against PostCSS then? I'm happy to do so if that's the case.

@sapphi-red
Copy link
Member

@reintroducing Yes. Would you report it to postcss-modules?

@reintroducing
Copy link
Author

@sapphi-red I went ahead and opened madyankin/postcss-modules#136. Closing this as it is not a Vite issue. Thank you.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2022
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 feat: css
Projects
None yet
Development

No branches or pull requests

2 participants