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.

warning: "@charset" must be the first rule in the file (2.6.x regression ?)

See original GitHub issue

Describe the bug

npm run build shows 100 warnings with

 > <stdin>:15:7495: warning: "@charset" must be the first rule in the file
    15 │ ...transform:rotate(0)}to{transform:rotate(2turn)}}@charset "UTF-8";/*!
       ╵                                                    ~~~~~~~~
   <stdin>:15:6767: note: This rule cannot come before a "@charset" rule
    15 │ ...t:attr(data-deselect);color:#fff}.multiselect-enter-active,.multi...

Appears to be a regression in 2.6.x

To reproduce:

npm init vite@latest my-vue-app -- --template vue

then add just 3 libraries to package.json and main.js

Minimal repo: https://github.com/mariusa/vite-warn

npm install
npm run build

FYI Also tried adding this to vite.config.js, which is not a solution (hiding the warnings instead of fixing the cause)

css: { preprocessorOptions: { scss: { charset: false } } }

but has no effect on warnings.

Previous reports, closed: https://github.com/vitejs/vite/issues/5519

Could this be caused by https://github.com/postcss/postcss-import ? FYI https://github.com/sass/dart-sass/issues/567#issuecomment-1003198108

Reproduction

https://github.com/mariusa/vite-warn

System Info

to proceed? (y) y

  System:
    OS: Linux 5.14 Fedora Linux 35 (Workstation Edition Prerelease)
    CPU: (8) x64 AMD Ryzen 7 4700U with Radeon Graphics
    Memory: 1.58 GB / 15.00 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.10.0 - /usr/bin/node
    npm: 7.24.0 - /usr/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Firefox: 93.0
  npmPackages:
    @vitejs/plugin-vue: ^2.0.0 => 2.0.1 
    vite: ^2.7.2 => 2.7.10

Used Package Manager

npm

Logs

vite v2.7.10 building for production...
✓ 78 modules transformed.
rendering chunks (1)...warnings when minifying css:
 > <stdin>:15:7495: warning: "@charset" must be the first rule in the file
    15 │ ...transform:rotate(0)}to{transform:rotate(2turn)}}@charset "UTF-8";/*!
       ╵                                                    ~~~~~~~~
   <stdin>:2:0: note: This rule cannot come before a "@charset" rule
     2 │ a[data-v-3d3c9e2e] {
       ╵ ^


 > <stdin>:15:7495: warning: "@charset" must be the first rule in the file
    15 │ ...transform:rotate(0)}to{transform:rotate(2turn)}}@charset "UTF-8";/*!
       ╵                                                    ~~~~~~~~
   <stdin>:6:0: note: This rule cannot come before a "@charset" rule
     6 │ #app {
       ╵ ^
...

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

19reactions
agileagocommented, Dec 31, 2021

vite.config.ts

css: {
    postcss: {
      plugins: [
        {
          postcssPlugin: 'internal:charset-removal',
          AtRule: {
            charset: (atRule) => {
              if (atRule.name === 'charset') {
                atRule.remove();
              }
            }
          }
        }
      ]
    }
}
3reactions
bluwycommented, Feb 22, 2022

According to the esbuild warning, it seems like esbuild has a hard stance that that’s how @charset would work (likely by a spec). So I doubt esbuild will be fixing that soon. So I think the correct solution is to disable the charset through preprocessorOptions.

I didn’t need a postcss plugin to fix it though, but specifying the config for both sass and scss worked for me:

css: {
  preprocessorOptions: {
   sass: { charset: false },
   scss: { charset: false },
  },
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

charset - CSS: Cascading Style Sheets - MDN Web Docs
The @charset CSS at-rule specifies the character encoding used in the style sheet. It must be the first element in the style sheet...
Read more >
News — JRuby.org
JRuby 9.3.x is compatible with Ruby 2.6.x and stays in sync with C Ruby. ... the jruby parser: it warns me about “warning:...
Read more >
The java Command - Oracle Help Center
The class to be executed is the first top-level class found in the source file. It must contain a declaration of the standard...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
systemPrefs with at least two files" status:RESOLVED resolution:OBSOLETE ... with version 2.6.13.x" status:RESOLVED resolution:OBSOLETE severity:critical ...
Read more >
Requests Documentation - Read the Docs
Warning : The private key to your local certificate must be unencrypted. ... Requests will first check for an encoding in the HTTP...
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