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.

[Storybook 6.0.0-rc.0] build fails on sass-loader

See original GitHub issue

Describe the bug I’m testing upgrading my storybook 5.3 repo to 6. I haven’t changed the webpack.config.js, but Storybook fails on build with:

Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @import "../../../assets/mixins";

Code snippets

const path = require("path");
const webpack = require('webpack');
const config = require('../package.json');

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        loaders: ["style-loader", "css-loader", "sass-loader"],
        include: path.resolve(__dirname, "../"),
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              sourceMap: true,
            },
          },
        ],
      },
      {
        test: /\.(ttf|eot|png|svg|gif|ico|woff(2)?)(\?[a-z0-9=&.]+)?$/,
        loader: 'file-loader?name=[name].[ext]',
      }
    ]
  },
  plugins: [
    new webpack.DefinePlugin({
      VERSION: JSON.stringify(config.version),
    }),
  ],
};

System: Environment Info:

System: OS: macOS Mojave 10.14.6 CPU: (12) x64 Intel® Core™ i9-8950HK CPU @ 2.90GHz Binaries: Node: 10.21.0 - /usr/local/bin/node Yarn: 1.18.0 - /usr/local/Cellar/yarn/1.22.4/bin/yarn npm: 6.14.4 - /usr/local/bin/npm Browsers: Chrome: 83.0.4103.116 Edge: 81.0.416.77 Firefox: 76.0.1 Safari: 13.1.1 npmPackages: @storybook/addon-a11y: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-actions: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-backgrounds: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-docs: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-knobs: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-links: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-notes: 6.0.0-rc.0 => 6.0.0-alpha.6 @storybook/addon-options: 6.0.0-rc.0 => 6.0.0-alpha.29 @storybook/addon-storyshots: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-storysource: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addon-viewport: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/addons: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/react: 6.0.0-rc.0 => 6.0.0-rc.0 @storybook/source-loader: 6.0.0-rc.0 => 6.0.0-rc.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

12reactions
disguised-uchihacommented, Jun 2, 2021

Previously you could do:

// webpack.config.js 
const path = require("path");
const webpack = require('webpack');
const config = require('../package.json');

module.exports = {
  // ...
};

That’s no longer supported, this is the new way:

// .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;
  },
};

@ndelangen

SassError: expected "{".
  ╷
1 │ import api from "!../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
  │                                                                                         ^
  ╵
  src/index.scss 1:89  root stylesheet
    at processResult (/Users/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:700:19)
    at /node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:806:5
    at /Users/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /node_modules/sass-loader/dist/index.js:54:7
    at Function.call$2 (/node_modules/sass/sass.dart.js:93041:16)
    at _render_closure.call$0 (/node_modules/sass/sass.dart.js:81441:23)
    at Object.Primitives_applyFunction (/node_modules/sass/sass.dart.js:1124:30)
    at Object.Function_apply (/node_modules/sass/sass.dart.js:5894:16)
    at _callDartFunctionFast (/node_modules/sass/sass.dart.js:7596:16)
    at /node_modules/sass/sass.dart.js:7574:18
SassError: SassError: expected "{".

I’m facing the same issue. Any leads?

6reactions
productdevbookcommented, May 21, 2021

Previously you could do:

// webpack.config.js 
const path = require("path");
const webpack = require('webpack');
const config = require('../package.json');

module.exports = {
  // ...
};

That’s no longer supported, this is the new way:

// .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;
  },
};

@ndelangen

SassError: expected "{".
  ╷
1 │ import api from "!../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
  │                                                                                         ^
  ╵
  src/index.scss 1:89  root stylesheet
    at processResult (/Users/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:700:19)
    at /node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:806:5
    at /Users/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /node_modules/sass-loader/dist/index.js:54:7
    at Function.call$2 (/node_modules/sass/sass.dart.js:93041:16)
    at _render_closure.call$0 (/node_modules/sass/sass.dart.js:81441:23)
    at Object.Primitives_applyFunction (/node_modules/sass/sass.dart.js:1124:30)
    at Object.Function_apply (/node_modules/sass/sass.dart.js:5894:16)
    at _callDartFunctionFast (/node_modules/sass/sass.dart.js:7596:16)
    at /node_modules/sass/sass.dart.js:7574:18
SassError: SassError: expected "{".
Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - npm install fails with Conflicting peer dependency
I have changed node-sass version to be compatible with my node version and this error went away. and the build is successful.
Read more >
module build failed: typeerror [err_invalid_arg_type]: the " ...
I'm pretty new to react and am having some issues with web pack. All I'm trying to do is import a SVG file...
Read more >
Compare Versions | @elliemae/pui-cli | npm
Warning. @elliemae/pui-cli 1.0.0-beta.51 is deprecated. ... GHSA-r8f7-9pfq-mjmvImproper Certificate Validation in node-sass ... @npmcli/run-script 6.0.0.
Read more >
wait until bundle finished, stopped at 99% [webpack 5] ...
I am also facing the above issue as well, no error information, ... module, false); <i> [webpack-dev-middleware] wait until bundle finished 10% building...
Read more >
Podman: Difficulty installing Forem on Ubuntu 18.04 TLS
This is the first error that shows up when using Podman to build and ... peer dependency "webpack@>=2". warning " > file-loader@6.0.0" has ......
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