【发布时间】:2021-11-04 04:17:08
【问题描述】:
我收到以下错误:
./styles/globals.scss
Global CSS cannot be imported from files other than your Custom <App>.
Due to the Global nature of stylesheets, and to avoid conflicts,
Please move all first-party global CSS imports to pages/_app.js.
Or convert the import to Component-Level CSS (CSS Modules).
Read more: https://nextjs.org/docs/messages/css-global
Location: pages/_app.tsx
当我在_app.tsx 中注释掉以下行时,此错误消失了
// import "@styles/globals.scss";
但是注意到样式表没有被应用。任何想法如何解决这个问题?
这是我的npm list的输出
$ npm list --depth 0
├── @types/react@17.0.20
├── eslint-config-next@11.1.2
├── eslint@7.32.0
├── next@11.1.2
├── react-dom@17.0.2
├── react@17.0.2
├── sass@1.39.0
└── typescript@4.4.2
$ npm list -g --depth 0
/Users/glaksmono/.nvm/versions/node/v16.8.0/lib
└── npm@7.22.0
【问题讨论】:
-
正如错误所说,将导入移动到
_app.js -
嗨@Nico - 导入已经在
_app.tsx中,我尝试将其重命名为 .js 但随后所有 ASX 系统税都会被破坏 -
尝试在根目录下创建css文件并像
import '../style.css'in_app.jsx一样导入 -
@SandipNirmal 仍然收到此错误
event - build page: /next/dist/pages/_error wait - compiling... error - ./test.css Global CSS cannot be imported from files other than your Custom <App>. Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules). Read more: https://nextjs.org/docs/messages/css-global Location: pages/_app.tsx -
既然一切看起来都正确,你能尝试一次干净的重启吗?删除
node_modules、.next,然后执行npm i、npm run dev
标签: node.js typescript next.js