28

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

2
  • What happens if you surround the <div> (and all the return value) in <> and </>? Commented Jan 23, 2023 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. Commented Jan 23, 2023 at 22:22

6 Answers 6

12

enter image description here

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

Sign up to request clarification or add additional context in comments.

3 Comments

haha, nextjs error reporting is amusing.
It's funny I've searched for this issue separately twice and come to this same answer! @next / react really need to improve reporting.
my case: added <hr> instead of <hr />
6

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

1 Comment

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

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

Comments

0

First of all check the typeof dataUseCases in your code and It must be an array.


You can try <></> and maybe fixed.

But this error happened when you have mistakes on your map and not actually related to your JSX okay?!

Comments

-1

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

1 Comment

You'll end up with the same issue
-1

it look like you run yarn start or npm run start instead yarn dev or npm run dev.

You try to run build dist on env dev that transpilation not executed before to build dist directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.