简体   繁体   English

Storybook React SassError:预期的“{”

[英]Storybook React SassError: expected "{"

Trying to setup a Storybook using .scss file.尝试使用.scss文件设置故事书。

Following the doc >按照文档>

// .storybook/main.js

const path = require('path');

// Export a function. Accept the base config as the only param.
module.exports = {
  webpackFinal: async (config, { configType }) => {
    // `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
    // You can change the configuration based on that.
    // 'PRODUCTION' is used when building the static version of storybook.

    // Make whatever fine-grained changes you need
    config.module.rules.push({
      test: /\.scss$/,
      use: ['style-loader', 'css-loader', 'sass-loader'],
      include: path.resolve(__dirname, '../'),
    });

    // Return the altered config
    return config;
  },
};

Give me this error: SassError: expected "{".给我这个错误: SassError: expected "{".

All solution found seems outdated and it looks like there might be an issue with react-script "style-loaded" package somehow?找到的所有解决方案似乎都已过时,并且看起来 react-script“样式加载”package 可能存在问题?

I guess styled-component is the way to go now.我猜styled-component现在是通往 go 的方式。

I had the same problem.我有同样的问题。 In my case the error was thrown because misalignment between the version of Webpack used by my project and the version of Webpack used by Stylebook to build the problem.在我的情况下,抛出错误是因为我的项目使用的 Webpack 版本与 Stylebook 用于构建问题的 Webpack 版本之间未对齐。

I fixed it installing Storybook that used Webpack5: https://storybook.js.org/blog/storybook-for-webpack-5/我修复了安装使用 Webpack5 的 Storybook: https://storybook.js.org/blog/storybook-for-webpack-5/

Another possible fix to use css-modules, in case you need it, is to rename files in *.module.scss and there is a built-in rule in Stylebook that compile it as module.如果需要,使用 css-modules 的另一个可能的修复方法是重命名*.module.scss中的文件,并且 Stylebook 中有一个内置规则将其编译为模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM