Hritik Jaiswal
Hritik Jaiswal

Reputation: 11

As soon as I installed nextjs there was a globals.css error without ever interfering with the code

The link to that repository is here. After creating the next.js environment using "npx create-next-app@latest ./" and running "npm run dev". The very basic commands to run, This error pops up:- `

../../../#React Projects/My projects/causs/styles/global.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: ..\..\..\#React Projects\My projects\causs\pages\_app.js

The code in _app.js is default that comes while creating next.js

import '../styles/global.css'

export default function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

the code in index.js is same, which comes as default:

import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

export default function Home() {
  return (
    <div className={styles.container}>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <main className={styles.main}>
        <h1 className={styles.title}>
          Welcome to <a href="https://nextjs.org">Next.js!</a>
        </h1>

        <p className={styles.description}>
          Get started by editing{' '}
          <code className={styles.code}>pages/index.js</code>
        </p>

        <div className={styles.grid}>
          <a href="https://nextjs.org/docs" className={styles.card}>
            <h2>Documentation &rarr;</h2>
            <p>Find in-depth information about Next.js features and API.</p>
          </a>

          <a href="https://nextjs.org/learn" className={styles.card}>
            <h2>Learn &rarr;</h2>
            <p>Learn about Next.js in an interactive course with quizzes!</p>
          </a>

          <a
            href="https://github.com/vercel/next.js/tree/canary/examples"
            className={styles.card}
          >
            <h2>Examples &rarr;</h2>
            <p>Discover and deploy boilerplate example Next.js projects.</p>
          </a>

          <a
            href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
            target="_blank"
            rel="noopener noreferrer"
            className={styles.card}
          >
            <h2>Deploy &rarr;</h2>
            <p>
              Instantly deploy your Next.js site to a public URL with Vercel.
            </p>
          </a>
        </div>
      </main>

      <footer className={styles.footer}>
        <a
          href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
          target="_blank"
          rel="noopener noreferrer"
        >
          Powered by{' '}
          <span className={styles.logo}>
            <Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
          </span>
        </a>
      </footer>
    </div>
  )
}

` Anything else you can see by going through the repository.

The next.config.js file is also default one. `

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
}

module.exports = nextConfig

I have installed latest version of node - v18.12.1 and npm - 8.19.2 Please help, I've no idea what to do. except adding and removing

import '../styles/global.css'

` in pages/_app.js file.

In conclusion, a newbie with next.js who has only created two projects, tried "npx create-next-app@latest ./" and then when I ran the environment it resulted with `

../../../#React Projects/My projects/causs/styles/global.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: ..\..\..\#React Projects\My projects\causs\pages\_app.js

` I haven't made any changes at all, the code and files in the project was by default. Note: I tried running my previous project too on my pc, which resulted in same error while it seems to do just fine where I've published.

Upvotes: 0

Views: 1285

Answers (1)

Hritik Jaiswal
Hritik Jaiswal

Reputation: 11

As it turns out the problem was in parent directory name;

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).

The cause of this error is peculiar, which I can't fathom. The parent directory as over here -

/#React Projects/My projects/causs/styles/global.css;

"React Projects" has a special character in it which caused the error to pop up once I removed it, the problem was over and my new and old projects are working just fine now.

Upvotes: 0

Related Questions