How to solve "semi-colon expected" warnings (css-semicolonexpected)

vue.jsVuejs2nuxt.jsTailwind Css

vue.js Problem Overview


I'm trying to use Tailwindcss @apply directive in a <style> tag of a Nuxt.js Vue file. Everything works fine, but I keep getting some annoying red squiggly lines. Please, guys, I need help... Thank you!

Below is a screenshot and a snippet:

enter image description here

<style scoped>

.title {
  @apply text-orient font-light block text-5xl pt-2;
}

.message {
  @apply font-light pb-4 text-orient text-2xl text-blue-bayoux
}
</style>

vue.js Solutions


Solution 1 - vue.js

There is no built-in way to solve this within VS Code. The recommended way to solve this is by making use of the Stylelint extension to handle your CSS linting (& SCSS and/or Less, etc.). It's very powerful and likely will improve your stylesheets beyond removing these errors for you.

  1. You need to add the styleint dependencies to your project. Run:
npm install --save-dev stylelint stylelint-config-standard

yarn add -D stylelint stylelint-config-standard
  1. Create a stylelint.config.js in the root of your project. (same location where your package.json is stored)

Place this snippet into it:

module.exports = {
  extends: ["stylelint-config-standard"],
  rules: {
    "at-rule-no-unknown": [
      true,
      {
        ignoreAtRules: [
          "tailwind",
          "apply",
          "variants",
          "responsive",
          "screen",
        ],
      },
    ],
    "declaration-block-trailing-semicolon": null,
    "no-descending-specificity": null,
  },
};

  1. Install these extensions to your VS Code setup:
  1. Last but not least, adjust your local or global VS Code settings.json file to include:
"css.validate": false,
"less.validate": false,
"scss.validate": false,

This way you will have the native linting "disabled", but are still ensuring it is linted using the Tailwind IntelliSense plugin.

Solution 2 - vue.js

I found another solution Usage of Tailwind with nuxt lead to weird @apply issue #300

Just add lang="postcss" to style tag and with this fix, I haven't any error.

<style lang="postcss" scoped>
  .title {
      @apply text-purple-600 font-bold;
  }
</style>

Solution 3 - vue.js

Disable Vetur's style validation

Such CSS warnings may originate from the Vetur extension, which may very well be the case if the warning's icon (as seen in VSCode's "Problems" pane) is a Vue logo.

By disabling Vetur's style validation, you may lose other benefits. Although, in the long-run, it's probably better to rely on a more full-featured validator/linter than this extension.

  1. Go to the Vetur extension settings and uncheck the option for style validation.

--- or ---

  1. Set the option per-project, in a .vscode/settings.json file in the project root, with the following:

    "vetur.validation.style": false


Vetur warnings look something like:

vetur is the guilty one here

Solution 4 - vue.js

i think you are using prettier and that plugin get error when you make @apply in one line so try this:

<style scoped>
.title {
  @apply text-orient;
  @apply font-light;
  @apply block;
  @apply text-5xl;
  @apply pt-2;
}

.message {
  @apply font-light;
  @apply pb-4;
  @apply text-orient;
  @apply text-2xl;
  @apply text-blue-bayoux;
}
</style>

Solution 5 - vue.js

2 Steps

  1. Add the lines below into: .vscode > settings.json
"css.validate": false,
"less.validate": false,
"scss.validate": false,
  1. Install StyleLint Extension
https://marketplace.visualstudio.com/items/shinnn.stylelint

Restart, it's done!

Solution 6 - vue.js

I had the same problem with Nuxt and the solution was to follow the steps in this blog, the TL:DR is:

  1. Install the stylelint vscode extension
  2. Add this configuration in your stylelint.config.js
rules: {
   'at-rule-no-unknown': [
     true,
     {
       ignoreAtRules: [
         'tailwind',
         'apply',
         'variants',
         'responsive',
         'screen',
       ],
     },
   ],
   'declaration-block-trailing-semicolon': null,
   'no-descending-specificity': null,
 },
  1. In the vscode configuration uncheck the option css validate or add this to your vscode settings.json file "css.validate": false

with this steps all will work perfect.

Just in case, I had a problem with the prettier formatting too, and it was fixed with this option in my vscode settings.json file "vetur.format.defaultFormatter.html": "prettier",

Solution 7 - vue.js

Try adding the extension PostCSS Language Support; it adds support for modern and experimental CSS within Visual Studio Code.

Solution 8 - vue.js

I use VS Code and added the following to my settings:

"files.associations": {
  "*.vue": "html"
}

Afterwards, the error was gone.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKingsley F.D.View Question on Stackoverflow
Solution 1 - vue.jsChrisView Answer on Stackoverflow
Solution 2 - vue.jsEwilan R.View Answer on Stackoverflow
Solution 3 - vue.jskissuView Answer on Stackoverflow
Solution 4 - vue.jsAli HosseiniView Answer on Stackoverflow
Solution 5 - vue.jsPedro CardosoView Answer on Stackoverflow
Solution 6 - vue.jsOscar VelandiaView Answer on Stackoverflow
Solution 7 - vue.jsImane ErguitiView Answer on Stackoverflow
Solution 8 - vue.jsmfeyxView Answer on Stackoverflow