Open Gr1mmz opened 1 year ago
UPDATE 07.14.
I've rollback changes in next.config.js
and and imports in all styles.
But now when I run storybook dev
it's doesn't load my global reset styles that I have in styles/app.scss
.
I clear all of my preview.js
file and now it has only one line:
import 'styles/app.scss';
Storybook is running, I can see all stories with my styles inside modules scss. But without reset styles it looks ugly.
Besides this, in browser console I have strange error
[HMR] bundle 'preview' has 2 warnings
client.js:197
./node_modules/@storybook/nextjs/dist/chunk-YPQDI6HO.mjs 1:224-231
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/@storybook/nextjs/dist/chunk-YPQDI6HO.mjs 1:353-360
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
UPDATE 07.17
After 3 days of trying I've found the issue.
I used sideEffects
flag in package.json
file for split all next.js pages on chunks and allow tree shaking automaticly. Without this flag Storybook works correctly. When I set sideEffects: false
application works perfect in dev and prod mode, but Storybook doesn't load some styles, for example - app.scss
file, which I described above.
Greetings! I managed to solve the specified problem, everything is the same, only I did not use sideEffects: false
in package.json
.
The solution was this:
@storybook/addon-styling
;main.js
such lines:{
name: '@storybook/addon-styling',
options: {
sass: {
// Require your Sass preprocessor here
implementation: require('sass'),
additionalData: `@import "./src/china/static/vars.scss";
`,
},
}
}
The additionalData string:@import "./src/china/static/vars.scss";
just solves our problem!
This solved the problem, and I did not specify root.scss, but the one that the error led to.
For anyone running into this issue, @Hebmor solution worked for me too!
Describe the bug
I use NextJS 12 with absolute imports, SCSS modules and latest version of Storybook. After add in
next.config.js
this:and delete this imports inside all style modules my project works perfect. But Storybook drop me this error in console:
The same error for all mixins I used.
My
main.ts
file is very simple:And
preview.js
is simple too:In
preview.js
file I've imported scss files like this:I've tried add a
webpackFinal
config inmain.ts
file of Storybook for adding the same imports that I add innext.config.js
. It gave me an another error:Before I delete variables imports from every module file Storybook works great. What am I doing wrong?
To Reproduce
I can't give a reproduction, because this is a commercial project.
System
Additional context
No response