10

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

ruffin
  • 16,507
  • 9
  • 88
  • 138
Karthik S
  • 111
  • 1
  • 1
  • 3
  • What happens if you surround the `
    ` (and all the return value) in `<>` and `>`?
    – ruffin Jan 23 '23 at 22:17
  • 1
    You've mashed two completely different error messages which should be two questions into a single question here. You should expect your question to be closed as "Needs more focus". You should edit it to focus on one problem, then consider asking another question about your other problem. – Quentin Jan 23 '23 at 22:22

5 Answers5

4

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

Mohammad
  • 722
  • 1
  • 8
  • 17
  • 1
    the "Expected JSX Identifier" error is actually kind of a misnomer... the JSX component is there, but has an error within it... so the compiler is confused and thinks the jsx isn't even there (because it can't identify it as a jsx component) So once you remove the former issue, the latter should go away. I have these "JSX Identifer" errors when i add a prop with an empty value or have an egregious typo somewhere in the code (an errant symbol somewhere) – K.H. B Jun 23 '23 at 15:23
2

Put your code inside

<></>

like this:

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>
    </>
  )
}
0

break byte case catch char class* const continue debugger default delete do double else enum* eval export* extends* false final finally float for function goto if implements import* in instanceof int interface let* long native new null package private protected public return short static super* switch synchronized this throw throws transient true try typeof var void abstract arguments await* boolean volatile while with yield

all these keywords are reserved in javaScript you cannot use them as variables, labels, or function names

Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38
0

I was encountering the same error. For me solving the other error fixed the Unexpected token div error. For me the other error was somewhat similar i.e. it has to do something with the arrow function.

0

enter image description here

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

Sergii Sechka
  • 499
  • 1
  • 4
  • 6