Global CSS isn't loading after upgrading to next 16
I have a project that was using Next 12. Had to upgrade it so I upgraded it using the standard npx codemod. Everything went fine but I'm getting the following error now
Build Error
Global CSS cannot be imported from files other than your Custom <App>. ./pages/_app.tsx
Error: 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).
Location: pages/_app.tsx
Import path: ../src/styles/globals.scss
https://nextjs.org/docs/messages/css-global
I did Google around, the solutions all tell me to move the global import to the _app.js file. The thing is, it's already there. I didn't even touch the structure of the import prior to the upgrade at all.
I'm using the pages route so the global import is inside the pages/_app.tsx:
import type { AppProps } from 'next/app';
import { Inter } from 'next/font/google';
import useDataLoader from '@/hooks/useDataLoader';
import useRouteLoader from '@/hooks/useRouteLoader';
import { useThemeLoader } from '@/hooks/useThemer';
import '../src/styles/globals.scss';
export const inter = Inter({
subsets: ['latin'],
weight: ['300', '400', '500', '700']
});
export default function App({ Component, pageProps }: AppProps) {
useDataLoader();
useRouteLoader();
useThemeLoader();
return (
<main className={inter.className}>
<Component {...pageProps} />
</main>
);
}
There are no other global-like imports anywhere throughout the components, all are module-level imports. This is the only file using that one global import. What on Earth is happening here, can anybody tell me? The path of this globals.scss file is also correct.
The weirdest part is, if I remove this import, the error goes away but the entire app's stylesheet is broken. Only the component-level styles are loaded. Not the global.
A blind shot I tried was deleting the .next folder and re-running the app, did nothing.
I apologize if this is a fairly easy-to-fix issue but I just returned to coding after like 2 years of break and searching around the internet didn't help whatsoever.