Sass error expected

SASS Expected identifier: Does Not accept number and letters in same map key? #2956 Comments How can I use number and letter in same map key? The text was updated successfully, but these errors were encountered: Same problem here . I try to declare a mixin: But get the error Identifier expected yeah I […]

Содержание

  1. SASS Expected identifier: Does Not accept number and letters in same map key? #2956
  2. Comments
  3. SyntaxError: Unexpected identifier #55
  4. Comments
  5. Preconditions
  6. Given
  7. Finally
  8. Footer
  9. Uncaught SyntaxError: Unexpected identifier — что это означает?
  10. Что делать с ошибкой Uncaught SyntaxError: Unexpected identifier
  11. Попробуйте сами
  12. SyntaxError: Unexpected identifier #55
  13. Comments
  14. Preconditions
  15. Given
  16. Finally
  17. Footer
  18. treeShake option gives SassError: Expected identifier #439
  19. Comments

SASS Expected identifier: Does Not accept number and letters in same map key? #2956

How can I use number and letter in same map key?

The text was updated successfully, but these errors were encountered:

Same problem here . I try to declare a mixin:

But get the error Identifier expected

yeah I googling this problem with different tricks but didn’t work I wish the sass support team looking to this problem.

Yeah let’s hope. Of course there is a simple solution to rename it (e.g. ‘xxl’ or ‘xl2), but I don’t like that name-giving. On some pages I read that Sass/SCSS simply doesn’t support mixins that start with an number/integer. But I dont’ get it how libraries like TailwindCSS use the variable ‘2xl’:

As you can see they declare the 2xl different from the others as a string

yeah but it still the same problem even If I declared it as a string
Identifier expected

Although they may look similar, these are two different issues.

@dennisfrijlink A mixin’s name needs to be a valid Sass identifier. Since 2xl starts with a number, it is not a valid identifier.

@devhoussam This is supported behavior. What version of Sass are you using? Are you sure that the $breakpoints map declaration is breaking? It could be the case that your code is breaking somewhere else by trying to use $breakpoints incorrectly.

@Awjin First thanks for your anwser. So if declare the breakpoints into an array like:

I can use a Sass map function to declare a mixin for every breakpoint (even for ‘2xl’)?

No, dynamic mixin invocation is not yet supported. See the issue here: #626

Aaah okay. You maybe know an altnernative to use the name ‘2xl’?

I use the mixins for defining the viewports so for example:

With the variable: $screen-xl-min: 1280px;

Here is A full example :

Sass Version : «sass»: «^1.29.0»,

The problem is that you are using the map keys to generate a class name – and CSS does not allow class names to start with a number. If you put a prefix on the class-name (like .media-#<$infix>-color-red ) it will work fine. (with or without the quotes in your map).

Maybe an idea how tailwindCSS uses the classname .2xl (check image below)?

@mirisuzanne is correct here. Since Sass is a superset of CSS, class names cannot start with a number.

Источник

SyntaxError: Unexpected identifier #55

Preconditions

  • node@5.11.0
  • jspm@0.17.0-beta.12
  • plugin-sass@0.4.3

Given

We have the following in jspm.config.js

We have a check-box-alpha.scss file within the package which contains the following

We have a CheckBoxAlpha.ts file next to the check-box-alpha.scss file with the following

In our console we execute the following command

Finally

In our console we see the following error

The text was updated successfully, but these errors were encountered:

  1. you are using jspm@0.17.0-beta.12 which is not released. It is still a beta and has bugs. Especially for plugins. Please use the latest stable version.
  2. you are importing wrong. Instead of import ‘./check-box-alpha.scss’; you have to do a import ‘./check-box-alpha.scss!’;
  3. you are using TypeScript. Please look at

Plugin uses ES6 syntax when installed #25 for a solution for that. jspm / SystemJS is based on ES5 / ES2015 and TypeScript as an optional plugin which causes issues with that.

Alright, as a sidenote, the issue is raised because with plugin-sass@0.4.0 works, and in regards the importing wrong, this is not necessary with the meta *.scss wildcard on my systemJS config.

Alright, as a sidenote, the issue is raised because with plugin-sass@0.4.0 works

Do you mean plugin-sass? Hm I don’t know what the do differently. Maybe we should look and compare it with this repo? Unfortunately I have no experience with TypeScript so I can’t help you out with your problem 😕 (I think this error is related to TypeScript because it can’t parse my script)

this is not necessary with the meta *.scss wildcard on my systemJS config.

Oh sorry, I oversight that 😔

Nope, with this library, on this release, works,unintentionally, but it does.

I’ll look into it and see what made it work before or made it fail now. I know TypeScript might not be a focus of the project but its a good to have for users.

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

Uncaught SyntaxError: Unexpected identifier — что это означает?

Вредная ошибка, которую легко исправить.

Допустим, у нас есть такой код на JavaScript:

После запуска в браузере код падает с ошибкой:

❌ Uncaught SyntaxError: Unexpected identifier

Это значит, что в коде появилась неизвестная переменная, команда или объект, о которых браузер не знает. Он не понимает, что за слово или символ он встретил, поэтому выводит такое сообщение.

👉 Скорее всего, в коде просто опечатка. Но имеет смысл проверить и другие возможности.

Что делать с ошибкой Uncaught SyntaxError: Unexpected identifier

Как и с большинством ошибок, браузер сообщает нам номер строки, где произошла ошибка. У нас это будет четвёртая строка:

Если нажмём на номер строки с ошибкой, браузер покажет нам подробности:

Мы видим, что браузер не понял, что за команды идут после ‘url(‘, поэтому подчеркнул их все красной линией. Похоже, он подумал, что мы хотели сообщить элементу fon стиль фона в виде текста url( — и всё, дальше закрылась кавычка. И что происходит дальше в коде, интерпретатору JavaScript непонятно. «Вы же закрыли кавычку, что вам от меня нужно?»

Конкретно в нашем примере программист пытается установить фон какого-то элемента, а в массиве backgrounds у него лежат адреса и названия файлов с фоном. Программист пытается подставить содержимое backgrounds внутрь инструкции CSS, но для этого нужно использовать плюсы (склеить строку). Без плюсов это всё считается как одна большая опечатка.

Правильно — вот так:

document.getElementById(‘fon’).style.background=’url(‘ + backgrounds[1] + ‘) bottom no-repeat’;

Но это конкретно в случае нашего кода. Unexpected identifier может появиться и в других случаях:

  • допущены опечатки;
  • лишние символы там, где их быть не должно;
  • наоборот, пропустили что-то нужное (например, плюс или запятую);
  • используется переменная или функция, которая не была объявлена выше;
  • пропущенная точка с запятой.

Попробуйте сами

Каждый из этих фрагментов кода даст ошибку Uncaught SyntaxError: Unexpected token. Попробуйте это исправить.

Источник

SyntaxError: Unexpected identifier #55

Preconditions

  • node@5.11.0
  • jspm@0.17.0-beta.12
  • plugin-sass@0.4.3

Given

We have the following in jspm.config.js

We have a check-box-alpha.scss file within the package which contains the following

We have a CheckBoxAlpha.ts file next to the check-box-alpha.scss file with the following

In our console we execute the following command

Finally

In our console we see the following error

The text was updated successfully, but these errors were encountered:

  1. you are using jspm@0.17.0-beta.12 which is not released. It is still a beta and has bugs. Especially for plugins. Please use the latest stable version.
  2. you are importing wrong. Instead of import ‘./check-box-alpha.scss’; you have to do a import ‘./check-box-alpha.scss!’;
  3. you are using TypeScript. Please look at

Plugin uses ES6 syntax when installed #25 for a solution for that. jspm / SystemJS is based on ES5 / ES2015 and TypeScript as an optional plugin which causes issues with that.

Alright, as a sidenote, the issue is raised because with plugin-sass@0.4.0 works, and in regards the importing wrong, this is not necessary with the meta *.scss wildcard on my systemJS config.

Alright, as a sidenote, the issue is raised because with plugin-sass@0.4.0 works

Do you mean plugin-sass? Hm I don’t know what the do differently. Maybe we should look and compare it with this repo? Unfortunately I have no experience with TypeScript so I can’t help you out with your problem 😕 (I think this error is related to TypeScript because it can’t parse my script)

this is not necessary with the meta *.scss wildcard on my systemJS config.

Oh sorry, I oversight that 😔

Nope, with this library, on this release, works,unintentionally, but it does.

I’ll look into it and see what made it work before or made it fail now. I know TypeScript might not be a focus of the project but its a good to have for users.

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

treeShake option gives SassError: Expected identifier #439

Module version
Nuxt 2.15.4
Nuxt/Vuetify 1.11.3

Describe the bug
every thing was fine and suddenly got these errors when deleted node_modules and package-lock.json and then used npm i and tried run the project via npm run dev or npm run build .

Screenshots

Additional context
this is my package.json file

and my nuxt.config

The text was updated successfully, but these errors were encountered:

faced the same problem in production. only occurs when using some components like v-tabs or v-select or v-autocomplete. others work fine.

@samanar , Mine was working just fine . when re-installed packages , BOOM!!
any idea?
tried «sass»: «^1.32.10», «sass-loader»: «^11.0.1» and achieved a new error!

Just created a fresh create-nuxt-app (with Vuetify) and everything is fine.
npm run dev and npm run build — no errors.

Same issue as @M-Barari with the exact same versions of Nuxt and nuxtjs/vuetify.

I noted that commenting the position: relative line solves the issue and allows me to finish the build correctly. Of course it is not viable

got same issue.
SassError: Expected identifier.

70 │ position: relative
│ ^

create a blank new nuxt app and call v-tabs in one of the pages. this error only occurs with some of the components. i tried downgrading various packages but no luck so far

Hi everyone, same issue for me —
I am hosting production website on Netlify —
npm run dev works fine on Local dev
npm run generate did not work but now is working on Local dev — I have no idea why exactly.
Maybe because I added the following in my nuxt.config.js
// Build Configuration: https://go.nuxtjs.dev/config-build build: < loaders: < sass: < sassOptions: < indentedSyntax: true >> > >
npm run generate on Netlify generates SassError as mentioned by @M-Barari
The error is directly connected to the Vuetify components one is using in his Layout.
For me this is V-Tabs ( V-Window), but there are surely others that are involved.

Duplicate issue with #438

/assets/variables.scss’],
treeShake: false,

Changing treeShake to false did the trick for me as well

Last night i finally found the culprit in my project by installing a fresh nuxt with vuetify and adding my packages and other files one by one! the only thing that i didn’t change was vuetify config in nuxt.config.js . so removed treeShake and every thing worked just fine.

Well , looks like it only solved the problem in dev ; by build i still got the error. so tried treeShake: false and problem solved in build too.

The issue is dart-sass, see sass/dart-sass#1287

In package.json add this to devDependendies:
«sass»: «1.32.8»

treeShake: false worked for me too. thanks . save my time.

Nothing is working for me. If i downgrade sass and sass loader now i have this. I am using owl preset and using a new nuxt app

Источник

image

use: sass-loader css-loader style-loader

package.json:

{
«css-loader»: «^3.6.0»,
«sass»: «^1.26.10»,
«sass-loader»: «^9.0.2»,
«style-loader»: «^1.2.1»
}

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I’m closing this. Please either update the issue with the template and reopen, or open a new issue.

I belive this is a legitimate issue and one without a work-around.

See my investigation on the ngx-markdown issue tracker. jfcere/ngx-markdown#252 (comment)

In my case, it surfaced with useages of sass modules being completely rejected after an upgrade of packages to support Angular v10, one of which started depending on node-sass.

@evilebottnawi I can open another issue if you want the full issue template filled out.

@robjtede You have invalid configuration css-loader twice applied

If that’s the underlying problem with this issue then my case is different. There’s definitely not two instances of css-loader.

ERROR in .../libs/.../src/index.scss (
     .../node_modules/css-loader/dist/cjs.js??ref--14-1
    !.../node_modules/postcss-loader/src??embedded
    !.../node_modules/resolve-url-loader??ref--14-3
    !.../node_modules/sass-loader/dist/cjs.js??ref--14-4
    !.../libs/.../src/index.scss
)

Module build failed (from .../node_modules/sass-loader/dist/cjs.js):
SassError: Invalid CSS after "  @include badge": expected "}", was ".load-host;"
        on line 4 of libs/.../src/lib/badge/badge.scss
        from line 1 of .../libs/.../src/index.scss
>>   @include badge.load-host;

SassError: Invalid CSS after » @include badge»: expected «}», was «.load-host;»

It is sass error, we can’t fix problems with your code, sorry

This is valid sass, supported by dart-sass as described in the comment I linked. I see this is not the right place to discuss the issue, sorry for the bother.

@robjtede node-sass and dart-sass have incompatibility with some syntaxes

I understand, but the fact is that if node-sass appears in the dependency tree, it is preferred over dart-sass. The error is thrown because node-sass is being used and doesn’t support sass modules.

Created a minimal reproduction repo: https://github.com/robjtede/repro-sass-loading

If you have problem with angular-cli, please open an issue in angular-cli repo

Yep, problem on angular-cli side

            {
                test: /.s(a|c)ss$/,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader'
                ],
            },
            {
                test: /.(jpe?g|gif|png|svg)$/,
                loader: 'url-loader',
                options: {
                    limit: 8 * 1024,
                    name: "[hash:10].[ext]",
                }
            },
            {
                exclude: /.(s?(a?|c)ss|js|html)$/,
                loader: 'file-loader',
                options: {
                    name: '[hash:10].[ext]'
                }
            }

exculde «css» or «scss» at file-loader

and its worked for me

file-loader 、css-loader was conflicted perhaps

@planAplan are you using storybook with Angular ?
I’ve tried your solution but it’s not working for me
here is my main.js file:

module.exports = {
    webpackFinal: async (config, { configType }) => {
    config.module.rules.push(
      {
        test: /.s(a|c)ss$/,
        use: ['style-loader', 'sass-loader', 'css-loader']
      },
      {
        test: /.(jpe?g|gif|png|svg)$/,
        loader: 'url-loader',
        options: {
          limit: 8 * 1024,
          name: '[hash:10].[ext]'
        }
      },
      {
        exclude: /.(s?(a?|c)ss|js|html)$/,
        loader: 'file-loader',
        options: {
          name: '[hash:10].[ext]'
        }
      }
    );

    // Return the altered config
    return config;
    },
    stories: ['../src/**/*.stories.mdx', '../src/**/*[email protected](js|jsx|ts|tsx)'],
    addons: ['@storybook/addon-links', '@storybook/addon-essentials']
};

and my preview.js file:

import { setCompodocJson } from '@storybook/addon-docs/angular';
import docJson from '../documentation.json';
import '@angular/localize/init';
setCompodocJson(docJson);

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' }
};

@planAplan are you using storybook with Angular ?
I’ve tried your solution but it’s not working for me
here is my main.js file:

module.exports = {
    webpackFinal: async (config, { configType }) => {
    config.module.rules.push(
      {
        test: /.s(a|c)ss$/,
        use: ['style-loader', 'sass-loader', 'css-loader']
      },
      {
        test: /.(jpe?g|gif|png|svg)$/,
        loader: 'url-loader',
        options: {
          limit: 8 * 1024,
          name: '[hash:10].[ext]'
        }
      },
      {
        exclude: /.(s?(a?|c)ss|js|html)$/,
        loader: 'file-loader',
        options: {
          name: '[hash:10].[ext]'
        }
      }
    );

    // Return the altered config
    return config;
    },
    stories: ['../src/**/*.stories.mdx', '../src/**/*[email protected](js|jsx|ts|tsx)'],
    addons: ['@storybook/addon-links', '@storybook/addon-essentials']
};

and my preview.js file:

import { setCompodocJson } from '@storybook/addon-docs/angular';
import docJson from '../documentation.json';
import '@angular/localize/init';
setCompodocJson(docJson);

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' }
};

i`ve never used storybook with Angular
but
Maybe it’s a problem with the order of loader parsing. You can try this

{
  test: /.s(a|c)ss$/,
  use: ['style-loader', 'css-loader', 'sass-loader' ]
}

I hope it helps you 🙏

If anyone lands here from webpacker 6 / rails, your issue might be that you are including css-loader in your custom webpacker configs. It is included already by webpacker, I believe.

Edit: I actually ended up opting out of the webpacker scss config entirely by adding this into base.js:

const scssConfigIndex = webpackConfig.module.rules.findIndex((config) => ".scss".match(config.test))
webpackConfig.module.rules.splice(scssConfigIndex, 1)

Not sure why this has been closed? There is no solution to the issue. I am also running into this.

Apparently I have fixed this by just setting this order to my style loaders, as the documentation
image

Apparently I have fixed this by just setting this order to my style loaders, as the documentation image

Yes — the order is a priority when dealing with loaders. :)
I’d consider this an answer to the question.

I’ve had same problem , first of all I’ve updated storybook webpack version to 5 , then I replaced styles ryles which was used by storybook webpack config , to rules , I use in my webpack config , belowe you can see my .storybook/main.js file

const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const rules = require('../webpack/rules');

module.exports = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*[email protected](js|jsx|ts|tsx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/preset-scss',
  ],
  core: {
    builder: 'webpack5',
  },
  webpackFinal: async (config) => {
    config.resolve.modules = [
      ...(config.resolve.modules || []),
      path.resolve(__dirname, '../src/client'),
    ];

    config.module.rules.push(rules.css());

    config.plugins.push(new MiniCssExtractPlugin());

    const newRules = config.module.rules.filter(
      (entity) =>
        ![/.css$/, /.s[ca]ss$/].some(
          (regExp) => regExp.toString() === entity.test.toString()
        )
    );

    return {
      ...config,
      module: {
        ...config.module,
        rules: newRules,
      },
    };
  },
};

webpack/rules.js

const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const css = () => {
  return {
    test: /.scss$/,
    use: [
      MiniCssExtractPlugin.loader,
      {
        loader: 'css-loader',
        options: {
          modules: true,
        },
      },
      {
        loader: 'sass-loader',
      },
    ],
  };
};

i had the same error, i added .scss to the css file on my laravel webpack.mix.js

mix.sass(‘resources/ui/frontend/css/frontend.scss‘, ‘public/assets/frontend/css’);

I am using webpack5, and encounter the same problem, the error caused by the false module’s rules, as follows:

截屏2022-02-20 14 47 22

The regular expression for css files should be /.css/i, haha.

I got this error, when I apply loaders to the same files twice.

// webpack.config.js with error
{
//...
  module: {
    rules: [
      {
        test: /.(scss|css)$/,
        use: ...
      },
      {
        test: /.module.(scss|css)$/,
        use: ...
      },
    ]
  }
}
// webpack.config.js without error
{
//...
  module: {
    rules: [
      {
        oneOf: [ // <---
          {
            test: /.(scss|css)$/,
            use: ...
          },
          {
            test: /.module.(scss|css)$/,
            use: ...
          },
        ]
      }
    ]
  }
}

I finally got storybook 6.5.9 and react 18.x to work.
I had to use a combination of most of the suggestions above…

Below is my .storybook/main.js

const path = require('path');

const alias = {
  'my-kit': path.resolve(__dirname, '../src'),
};

module.exports = {
  stories: [
    './stories/**/*.stories.mdx',
    './stories/**/*[email protected](js|jsx|ts|tsx)',
  ],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
    '@storybook/preset-create-react-app',
  ],
  framework: '@storybook/react',
  core: {
    builder: '@storybook/builder-webpack5',
  },
  webpackFinal: async (config) => {
    const scssConfigIndex = config.module.rules.findIndex((c) =>
      '.scss'.match(c.test),
    );
    if (scssConfigIndex > 0 && config.module.rules[scssConfigIndex]?.oneOf)
      config.module.rules[scssConfigIndex].oneOf.push({
        test: /.(css|s(a|c)ss)$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
        include: path.resolve(__dirname, '../'),
      });
    else
      config.module.rules.push({
        test: /.(css|s(a|c)ss)$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
        include: path.resolve(__dirname, '../'),
      });
    return {
      ...config,
      resolve: { ...config.resolve, alias },
    };
  },
};

I need to do some more work on the logic… But in my case I had to add the «loaders» into the oneOf rules that contained scss rules. Thank you @snowinmars for your work above.

ERROR Failed to compile with 1 error 12:40:40

error in ./src/assets/style.scss

Syntax Error: SassError: expected «}».

301 │ }
│ ^

src/assets/style.scss 301:2 root stylesheet

@ ./src/assets/style.scss 4:14-225 15:3-20:5 16:22-233
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.0.28:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

  • kalisto74

Здравствуйте.Начал изучать препроцессор Sass. Установил Sass(3.4.21v). При попытке задать переменную,всё пучком. Но когда на практике начинаю применять переменную в качестве стиля,появляется ошибка(скобки убирать пробовал).

$color: blue

h1 {
	color: $color
}

Ошибка такова:

"Error: Invalid CSS after "h1 ": expected selector or at-rule, was "{"A         on line 10 of C:/Users/Worddoc/Desktop/htmlandcss/sass/screen.scssA A 5: A 6: @import "compass/reset";A 7: A 8: $color: blueA 9: A 10: h1 {A 11: 	color: $colorA 12: }"; }

ПОМОГИТЕ!


  • Вопрос задан

    более трёх лет назад

  • 11026 просмотров

точка с запятой в конце сток обязательна

Пригласить эксперта

У вас синтаксис scss!
www.internet-technologies.ru/articles/article_1950.html

а вообще оба должны работать с модулем sass
но с вашим синтаксисом расширение файла должно быть .scss

и я бы писал так:

$color: blue;

h1 {
  color: $color;
}

поставьте себе линтер (scss-lint) — оно вам ошибки подробно опишет и также стилистические ошибки подсветит

Почитай про синтаксис. Вроде бы так:

$color: blue
h1
  color: $color


  • Показать ещё
    Загружается…

10 февр. 2023, в 04:49

50000 руб./за проект

10 февр. 2023, в 02:20

3000 руб./за проект

10 февр. 2023, в 01:33

1500 руб./за проект

Минуточку внимания

laihuamin opened this issue 3 years ago · comments

image

use: sass-loader css-loader style-loader

package.json:

{
«css-loader»: «^3.6.0»,
«sass»: «^1.26.10»,
«sass-loader»: «^9.0.2»,
«style-loader»: «^1.2.1»
}

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I’m closing this. Please either update the issue with the template and reopen, or open a new issue.

I belive this is a legitimate issue and one without a work-around.

See my investigation on the ngx-markdown issue tracker. jfcere/ngx-markdown#252 (comment)

In my case, it surfaced with useages of sass modules being completely rejected after an upgrade of packages to support Angular v10, one of which started depending on node-sass.

@evilebottnawi I can open another issue if you want the full issue template filled out.

@robjtede You have invalid configuration css-loader twice applied

If that’s the underlying problem with this issue then my case is different. There’s definitely not two instances of css-loader.

ERROR in .../libs/.../src/index.scss (
     .../node_modules/css-loader/dist/cjs.js??ref--14-1
    !.../node_modules/postcss-loader/src??embedded
    !.../node_modules/resolve-url-loader??ref--14-3
    !.../node_modules/sass-loader/dist/cjs.js??ref--14-4
    !.../libs/.../src/index.scss
)

Module build failed (from .../node_modules/sass-loader/dist/cjs.js):
SassError: Invalid CSS after "  @include badge": expected "}", was ".load-host;"
        on line 4 of libs/.../src/lib/badge/badge.scss
        from line 1 of .../libs/.../src/index.scss
>>   @include badge.load-host;

SassError: Invalid CSS after » @include badge»: expected «}», was «.load-host;»

It is sass error, we can’t fix problems with your code, sorry

This is valid sass, supported by dart-sass as described in the comment I linked. I see this is not the right place to discuss the issue, sorry for the bother.

@robjtede node-sass and dart-sass have incompatibility with some syntaxes

I understand, but the fact is that if node-sass appears in the dependency tree, it is preferred over dart-sass. The error is thrown because node-sass is being used and doesn’t support sass modules.

Created a minimal reproduction repo: https://github.com/robjtede/repro-sass-loading

If you have problem with angular-cli, please open an issue in angular-cli repo

Yep, problem on angular-cli side

            {
                test: /.s(a|c)ss$/,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader'
                ],
            },
            {
                test: /.(jpe?g|gif|png|svg)$/,
                loader: 'url-loader',
                options: {
                    limit: 8 * 1024,
                    name: "[hash:10].[ext]",
                }
            },
            {
                exclude: /.(s?(a?|c)ss|js|html)$/,
                loader: 'file-loader',
                options: {
                    name: '[hash:10].[ext]'
                }
            }

exculde «css» or «scss» at file-loader

and its worked for me

file-loader 、css-loader was conflicted perhaps

@planAplan are you using storybook with Angular ?
I’ve tried your solution but it’s not working for me
here is my main.js file:

module.exports = {
    webpackFinal: async (config, { configType }) => {
    config.module.rules.push(
      {
        test: /.s(a|c)ss$/,
        use: ['style-loader', 'sass-loader', 'css-loader']
      },
      {
        test: /.(jpe?g|gif|png|svg)$/,
        loader: 'url-loader',
        options: {
          limit: 8 * 1024,
          name: '[hash:10].[ext]'
        }
      },
      {
        exclude: /.(s?(a?|c)ss|js|html)$/,
        loader: 'file-loader',
        options: {
          name: '[hash:10].[ext]'
        }
      }
    );

    // Return the altered config
    return config;
    },
    stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
    addons: ['@storybook/addon-links', '@storybook/addon-essentials']
};

and my preview.js file:

import { setCompodocJson } from '@storybook/addon-docs/angular';
import docJson from '../documentation.json';
import '@angular/localize/init';
setCompodocJson(docJson);

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' }
};

@planAplan are you using storybook with Angular ?
I’ve tried your solution but it’s not working for me
here is my main.js file:

module.exports = {
    webpackFinal: async (config, { configType }) => {
    config.module.rules.push(
      {
        test: /.s(a|c)ss$/,
        use: ['style-loader', 'sass-loader', 'css-loader']
      },
      {
        test: /.(jpe?g|gif|png|svg)$/,
        loader: 'url-loader',
        options: {
          limit: 8 * 1024,
          name: '[hash:10].[ext]'
        }
      },
      {
        exclude: /.(s?(a?|c)ss|js|html)$/,
        loader: 'file-loader',
        options: {
          name: '[hash:10].[ext]'
        }
      }
    );

    // Return the altered config
    return config;
    },
    stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
    addons: ['@storybook/addon-links', '@storybook/addon-essentials']
};

and my preview.js file:

import { setCompodocJson } from '@storybook/addon-docs/angular';
import docJson from '../documentation.json';
import '@angular/localize/init';
setCompodocJson(docJson);

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' }
};

i`ve never used storybook with Angular
but
Maybe it’s a problem with the order of loader parsing. You can try this

{
  test: /.s(a|c)ss$/,
  use: ['style-loader', 'css-loader', 'sass-loader' ]
}

I hope it helps you 🙏

If anyone lands here from webpacker 6 / rails, your issue might be that you are including css-loader in your custom webpacker configs. It is included already by webpacker, I believe.

Edit: I actually ended up opting out of the webpacker scss config entirely by adding this into base.js:

const scssConfigIndex = webpackConfig.module.rules.findIndex((config) => ".scss".match(config.test))
webpackConfig.module.rules.splice(scssConfigIndex, 1)

Not sure why this has been closed? There is no solution to the issue. I am also running into this.

Apparently I have fixed this by just setting this order to my style loaders, as the documentation
image

Apparently I have fixed this by just setting this order to my style loaders, as the documentation image

Yes — the order is a priority when dealing with loaders. :)
I’d consider this an answer to the question.

I’ve had same problem , first of all I’ve updated storybook webpack version to 5 , then I replaced styles ryles which was used by storybook webpack config , to rules , I use in my webpack config , belowe you can see my .storybook/main.js file

const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const rules = require('../webpack/rules');

module.exports = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/preset-scss',
  ],
  core: {
    builder: 'webpack5',
  },
  webpackFinal: async (config) => {
    config.resolve.modules = [
      ...(config.resolve.modules || []),
      path.resolve(__dirname, '../src/client'),
    ];

    config.module.rules.push(rules.css());

    config.plugins.push(new MiniCssExtractPlugin());

    const newRules = config.module.rules.filter(
      (entity) =>
        ![/.css$/, /.s[ca]ss$/].some(
          (regExp) => regExp.toString() === entity.test.toString()
        )
    );

    return {
      ...config,
      module: {
        ...config.module,
        rules: newRules,
      },
    };
  },
};

webpack/rules.js

const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const css = () => {
  return {
    test: /.scss$/,
    use: [
      MiniCssExtractPlugin.loader,
      {
        loader: 'css-loader',
        options: {
          modules: true,
        },
      },
      {
        loader: 'sass-loader',
      },
    ],
  };
};

i had the same error, i added .scss to the css file on my laravel webpack.mix.js

mix.sass(‘resources/ui/frontend/css/frontend.scss‘, ‘public/assets/frontend/css’);

I am using webpack5, and encounter the same problem, the error caused by the false module’s rules, as follows:

截屏2022-02-20 14 47 22

The regular expression for css files should be /.css/i, haha.

I got this error, when I apply loaders to the same files twice.

// webpack.config.js with error
{
//...
  module: {
    rules: [
      {
        test: /.(scss|css)$/,
        use: ...
      },
      {
        test: /.module.(scss|css)$/,
        use: ...
      },
    ]
  }
}
// webpack.config.js without error
{
//...
  module: {
    rules: [
      {
        oneOf: [ // <---
          {
            test: /.(scss|css)$/,
            use: ...
          },
          {
            test: /.module.(scss|css)$/,
            use: ...
          },
        ]
      }
    ]
  }
}

I finally got storybook 6.5.9 and react 18.x to work.
I had to use a combination of most of the suggestions above…

Below is my .storybook/main.js

const path = require('path');

const alias = {
  'my-kit': path.resolve(__dirname, '../src'),
};

module.exports = {
  stories: [
    './stories/**/*.stories.mdx',
    './stories/**/*.stories.@(js|jsx|ts|tsx)',
  ],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
    '@storybook/preset-create-react-app',
  ],
  framework: '@storybook/react',
  core: {
    builder: '@storybook/builder-webpack5',
  },
  webpackFinal: async (config) => {
    const scssConfigIndex = config.module.rules.findIndex((c) =>
      '.scss'.match(c.test),
    );
    if (scssConfigIndex > 0 && config.module.rules[scssConfigIndex]?.oneOf)
      config.module.rules[scssConfigIndex].oneOf.push({
        test: /.(css|s(a|c)ss)$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
        include: path.resolve(__dirname, '../'),
      });
    else
      config.module.rules.push({
        test: /.(css|s(a|c)ss)$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
        include: path.resolve(__dirname, '../'),
      });
    return {
      ...config,
      resolve: { ...config.resolve, alias },
    };
  },
};

I need to do some more work on the logic… But in my case I had to add the «loaders» into the oneOf rules that contained scss rules. Thank you @snowinmars for your work above.

ERROR Failed to compile with 1 error 12:40:40

error in ./src/assets/style.scss

Syntax Error: SassError: expected «}».

301 │ }
│ ^

src/assets/style.scss 301:2 root stylesheet

@ ./src/assets/style.scss 4:14-225 15:3-20:5 16:22-233
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.0.28:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Sc556 ricoh error
  • Sc552 ricoh ошибка
  • Sc542 ошибка ricoh sp150
  • Sc542 ошибка ricoh sp 150w
  • Sc503 01 ricoh mp2001sp ошибка

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии