Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript Error : Unexpected token `div`. Expected jsx identifier

I was building a website based on nextjs-typescript and tailwindcss

and I am encountering this weird error Expression expected.

screenshot of error

I am also getting this in the terminal:

  Unexpected token `div`. Expected jsx identifier
  const UseCases = () => {
  7 |   return (
  8 |     <div className="relative z-10 bg-gray-100 py-20">
    :      ^^^
  9 |       <FadeIntoView>

This is my code

import dataUseCases from "../../data/cases.data"
import FadeIntoView from "../../utils/gsap/fadeIntoView"

import Cases from "./useCases"

const UseCases = () => {
  return (
    <div className="relative z-10 bg-gray-100 py-20">
      <FadeIntoView>
        <h2 className="xs:text-8xl text-22vw fill-color pb-7 text-right font-black">Case</h2>
        <div>
          {dataUseCases.map((case, index) => (<Cases key={case.title + "-" + index} index={index + 1}  />))}
        </div>
      </FadeIntoView>
    </div>
  )
}

export default UseCases

and the file is named index.tsx and is located inside src/components/useCase

Tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

I tried a few suggestions from

swc#issue-2237 stack-overflow

But none of them seem to work here

like image 721
Karthik S Avatar asked Sep 06 '25 09:09

Karthik S


2 Answers

enter image description here

For me it says - "Unexpected token header", but the actual problem in missing parameter on a property

like image 106
Sergii Sechka Avatar answered Sep 09 '25 03:09

Sergii Sechka


case is a reserved keyword in javascript change that variable in your map to something else

like image 38
Mohammad Avatar answered Sep 09 '25 03:09

Mohammad