Troubleshooting: TypeScript not functioning properly with Create Next App dev server启动时有问题

When I attempted to set up a nextjs+typescript app using the command npx create-next-app@latest --ts, all the installations went smoothly. However, upon running the dev function, I encountered an error related to Global CSS.

error - ../../../#Typescript/NextJsTS/ts-next/styles/globals.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-globalLocation: ..\..\..\#Typescript\NextJsTS\ts-next\pages\_app.tsx

Here is the structure of my folders-

•pages
      •api
      •_app.tsx
      •index.tsx
•styles
      •globals.css
      •Home.module.css
 

The content of my _app.tsx file is as follows-

import '../styles/globals.css'
import type { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
  return <Component {...pageProps} />
}

export default MyApp

I attempted to comment out the import of global.css but that led to another error. Check the error screenshot here.

Answer №1

It appears that the global.css file has been imported into multiple files. To resolve this issue, remove the import statements from all files except for the _app.tsx file. If this is your first time using Next.js, the application should function correctly without any additional modifications.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for setting up a nested route in Angular 2

I am currently working on a project that includes an admin page (check the file structure below). I am trying to set up a child route named 'createuser' for the admin page (localhost:4200/admin/createuser). Despite my attempts, I encountered an e ...

Verifying if posthog has been initialized

Is there a reliable method to verify whether Posthog has been initialized within the app? In my NextJS application, the structure is as follows: _app.tsx -> posthog initialization inside useEffect MyComponent-> event capture The event capture ...

Sort through the files for translation by utilizing a feature within Typewriter

I am looking to implement Typewriter in a project that involves translating many C# files into TypeScript using WebEssentials. Is there a way to configure the template so that only class files containing a specific attribute are translated in this mann ...

Confirm the presence of a particular sub collection within Firebase/Firestore by returning true

Can you confirm if the sub-collection named 'categories' exists within the users collection in Firestore? Please return true if it exists and false if it does not. ...

Issue "Module not found" arises while trying to import an external JSON file in TypeScript

Working with local JSON files is not an issue for me. I've successfully implemented the following code: import data from "./example.json"; However, I encounter an error when attempting to access remote files like the one below, resulting in a "Canno ...

The rapid execution of code causing an observable race condition

When exporting a CSV file in my code, I encounter a race condition while trying to modify some data before the export. The issue is that the id gets set correctly, but the number only updates after the method is called a second time. I believe the proble ...

Encountering a module error when using SignalR with Webpack and TypeScript: 'Unable to locate module './NodeHttpClient''

I am currently working on integrating a SignalR client into an Angular application using Webpack and TypeScript. Here is the content of my package.json file: { "private": true, "version": "0.0.0", "scripts": { "test": "karma start ClientApp/tes ...

Updating a global variable in Ionic 3

I recently started exploring the world of Ionic, Angular, and TypeScript. I encountered a scenario where I needed to have a variable "ar: AR" accessible across all pages. To achieve this, I decided to make it a global variable by following these steps: Fi ...

Issue: Resolution of multiple Storybook dependencies with Storybook 8 and PNPM could not be achieved

While integrating Storybook 8 with PNPM in my Next.js project, I am facing challenges with resolving dependencies. Despite multiple attempts to troubleshoot the issue, such as clearing caches, reinstalling dependencies, and experimenting with different ver ...

Error encountered in trpc version 10: The query data must be defined and cannot be left

Recently started using trpc and trying to implement basic query functionality, but it's not working as expected. I suspect there might be something missing in my setup. In version 9, I used createReactQueryHooks(), but I believe in version 10, you onl ...

The necessity for unique "key" props for every child in a list is generating an error within the custom component

When mapping over an array to render a custom card component for each index, I encountered an error stating "Each child in a list should have a unique key prop." Despite passing the index as the key and trying various methods like using React.Fragment or ...

Is it necessary for the React generic type prop to be an extension of another type

I have recently started using TypeScript and I am facing a confusion regarding passing generic types into my higher-order component (HOC). My objective is to pass the component props as a generic type in order to have the Component with those specific type ...

Develop a React application with updated image paths for routing

Currently, I am working on developing a lightbox using create-react-app and have encountered a major issue that is causing some complications. In the public folder, there are several images and I have a spinner file named Spinner-white.svg. The problem ari ...

Returning a 'never' type from a function in React using Typescript

Basically, I have a function that initiates the OAuth flow (redirecting to Google OAuth login page, for example): async function signIn() { // start OAuth flow } And let's say I want to use it in a useEffect hook like this: ... useEffect(() => { ...

Guide to turning off the previous button in FullCalendar using Angular 7 and TypeScript

Can someone help me with disabling the previous button on FullCalendar if I go back 2 months? For example, if it's currently April and I navigate to February, I want the previous button to be disabled. I have FullCalendar implemented, but all the sol ...

Encountering an "Undefined property" error in Angular when trying to read a property, even though the json-p

manager.ts export interface Manager { id: number; name: string; employees: Array<Employee>; } employee.ts export interface Employee { id: number; fullName: string; } managers.component.ts export class ManagersComponent implem ...

Successfully passing props to the image source using React/Next.js

Currently, in my implementation with React and Next.js, I am utilizing next-images for importing images. I am looking for a solution to pass data directly to the img src attribute, like so: <img src={require(`../src/image/${data}`)} /> It appears t ...

Angular 2's Dependency Injection injects functions instead of objects

My application has a 'store' service that depends on a 'repo' service. The issue I'm facing is that the 'store' service is being injected correctly, but the 'repo' service it receives appears to be a function in ...

Gaining entry to the REDUX state from a Higher Order Component

As a newcomer to the world of coding and React, I've hit a roadblock that I could use some help with. My goal is to create components that can be favorited and then displayed on a separate page. To achieve this, I am utilizing Redux to manage the st ...

What is the best way to retrieve the ID from router.push in Next.js on a different page?

Hello all, I am encountering an issue with accessing the ID from a dynamic page in Next.js within the Edit project page. Below is my file structure: https://i.sstatic.net/c4xoy9gY.png In order to navigate to the Edit project page, I have this component s ...