I feel completely lost.
Just to provide some background, I am working with Next and React.
// package.json
"dependencies": {
"@netlify/plugin-nextjs": "^3.4.2",
"next": "^10.0.0",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-preset-env": "^6.7.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-onclickoutside": "^6.11.2",
"react-svg": "14.0.0"
},
"devDependencies": {
"classnames": "^2.2.6",
"sass": "^1.34.0"
}
To test production locally, I use
npx next build && npx next start -p 4000
. Everything works smoothly in development using netlify dev -e
.
However, strange effects occur when I have two imports of .module.scss
, causing the client-side javascript to cease functioning.
For example, I have a page:
// /pages/test.js
import CompA from 'components/comp-a'
import CompB from 'components/comp-b'
And:
// /components/comp-a.js
import styles from 'components/comp-a.module.scss`
As well as:
// /components/comp-b.js
import styles from 'components/comp-b.module.scss`
This scenario displays correctly visually, but no client-side javascript functions are working without any visible errors. I spent the entire day troubleshooting by commenting out various components and lines of code to pinpoint this issue.
By commenting out one component import in the page, the client-side js works fine, but not with two.
Similarly, when I comment out the styles
import in one of the components, the client-side js starts functioning properly as well.
In another situation where it doesn't work:
// components/comp-a.js
import styles from 'components/comp-a.module.js'
import CompB from 'components/comp-b.module.js'
It works if I comment out either the style or the sub-component.
None of these solutions make sense because in the page, I also have the Layout
being imported, which contains its own styles
and that works perfectly fine.
What could possibly be the cause of all this confusion?
Edit:
Upon further investigation, I discovered that I was using @extend .class-abc
along with @import 'style/foo.module';
, and the .class-abc
contained another class:
// /style/foo.module.scss
.class-abc {
...
.bar {
...
}
}
Strangely, commenting out .bar
resolved the issue. I'm utterly puzzled by what is happening.