【发布时间】:2020-10-29 03:17:45
【问题描述】:
我来自 CRA 背景,正在使用 Next.js 9.4.2 版
我的项目树看起来像这样:-
pages/
_app.tsx
index.tsx
components/
Navbar/
index.ts
Navbar.tsx
Navbar.scss
在我的Navbar.tsx里面我有一个声明import './Navbar.scss';
这给了我以下错误:-
./src/components/Navbar/Navbar.scss
Global CSS cannot be imported from files other than your Custom <App>. Please move all global CSS imports to src/pages/_app.tsx.
Read more: https://err.sh/next.js/css-global
Location: src/components/Navbar/Navbar.tsx
如前所述,如果我将 import Navbar.scss 语句移至 pages/_app.tsx,错误就会消失
我知道我可以切换到Navbar.module.scss,但我不想走模块化 scss 的路线,因为我希望我的 scss 变得复杂我想坚持我编写 scss 的方式和不要一直为以后可能出现的问题寻找解决方法。我愿意在这里被说服,但我还没有找到很好的阅读资料来选择它作为我的道路。
所以从外观上看,我坚持将所有<component>.scss 文件导入_app.tsx。这将在我的_app.tsx 中留下一长串<component>.scss 导入,并且我还将留下许多可能有条件不渲染的组件的<component>.scss 文件。
我在这里有什么选择?
【问题讨论】:
-
似乎可以解决这个问题的解决方案在这里:stackoverflow.com/questions/45192088/…
-
你最终采用了什么解决方案?
-
@TaylorA.Leach 我用过
import styles from <component>.module.scss
标签: reactjs sass next.js server-side-rendering