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

Vite: "@charset" must be the first rule in the file #12867

Closed
maggie44 opened this issue Mar 20, 2022 · 5 comments
Closed

Vite: "@charset" must be the first rule in the file #12867

maggie44 opened this issue Mar 20, 2022 · 5 comments

Comments

@maggie44
Copy link
Contributor

What happened?

When building using Vite, the following message displays:

▲ [WARNING] "@charset" must be the first rule in the file

    <stdin>:68:0:
      68 │ @charset "UTF-8";
         ╵ ~~~~~~~~

  This rule cannot come before a "@charset" rule

    <stdin>:1:0:
      1 │ @font-face {
        ╵ ^

There is a proposed fix to consider as default: vitejs/vite#6333 (comment)

What did you expect to happen?

No need for these error messages to display.

Reproduction URL

Not applicable

How to reproduce?

Run quasar build on a new Quasar project using Vite (I chose Typescript but otherwise default settings).

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite)

Platforms/Browsers

No response

Quasar info output

No response

Relevant log output

No response

Additional context

No response

@github-actions
Copy link

Hi @Maggie0002! 👋

It looks like you provided an invalid or unsupported reproduction URL.
Do not use any service other than Codepen, jsFiddle, Codesandbox, and GitHub.
Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc.
Please edit your original post above and provide a valid reproduction URL as explained.

Without a proper reproduction, your issue will have to get closed.

Thank you for your collaboration. 👏

@smolinari
Copy link
Collaborator

@pdanpdan
Copy link
Collaborator

pdanpdan commented May 3, 2022

It looks like this works: https://lifesaver.codes/answer/build-includes-charset-problem-5833

In quasar.config.js under build key

{
  build: {
    extendViteConf(viteConf) {
      if (viteConf.css !== Object(viteConf.css)) {
        viteConf.css = {};
      }
      if (viteConf.css.postcss !== Object(viteConf.css.postcss)) {
        viteConf.css.postcss = {};
      }
      if (Array.isArray(viteConf.css.postcss.plugins) === false) {
        viteConf.css.postcss.plugins = [];
      }
      viteConf.css.postcss.plugins.unshift({
        postcssPlugin: 'internal:charset-removal',
        AtRule: {
          charset: (atRule) => {
            if (atRule.name === 'charset') {
              atRule.remove();
            }
          },
        },
      });
    },
  },
},

@smolinari
Copy link
Collaborator

@pdanpdan - Confirmed. This fixes the build warning. Thanks!

Scott

@maggie44
Copy link
Contributor Author

maggie44 commented May 3, 2022

I think there is an upstream fix coming for it too: vitejs/vite#6333 (comment) & vitejs/vite#7678

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

No branches or pull requests

3 participants