question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: Unexpected token with simple React/JSX component

See original GitHub issue

I’m a bit embarrassed having to open this issue here, but I’ve been stuck for a few hours. I have a trivial React component

import React from "react"
import { Trans } from "react-i18next"

export default function() {
  return (
    <div>
      <Trans i18nKey="key" />
    </div>
  )
}

and the latest versions of i18next and i18next-scanner. But all I get is

i18next-scanner: Unable to parse Trans component from "XXX/src/routes/Home/Component.js"
    SyntaxError: Unexpected token (7:20)

Any ideas what I might be doing wrong?

Version

  • i18next: 15.0.7
  • i18next-scanner: 2.10.0

Configuration

{
  input: [
    "src/routes/Home/Component.js",
  ],
  output: "./",
  options: {
    debug: true,
    func: {
      list: ["t"],
      extensions: [".js"],
    },
    trans: {
      component: "Trans",
      i18nKey: "i18nKey",
      extensions: [".js"],
    },
    lngs: ["en", "de"],
    ns: ["translations"],
    defaultLng: "de",
    defaultNs: "translations",
    defaultValue: "__STRING_NOT_TRANSLATED__",
    resource: {
      loadPath: "src/i18n/{{lng}}/{{ns}}.json",
      savePath: "src/i18n/{{lng}}/{{ns}}.json",
      jsonIndent: 2,
      lineEnding: "\n",
    },
    keySeparator: ".",
  },
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mistocommented, Mar 16, 2019

That did it! 😃 Thank you very much!

0reactions
cutterblcommented, Jun 20, 2019

@kenzouno1 I had the same issue. I completely removed my ‘lock’ file, deleted node-modules, reinstalled (including latest acorn as a dependency), and still got the errors. I finally got around it by adding a “resolutions” entry to my package.json, pointing to the internal acorn version.

"resolutions": {
    "i18next-scanner/**/acorn": "6.1.1"
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS: "Uncaught SyntaxError: Unexpected token <"
However, when I tried to put my JS in a separate file, I started getting this error: "Uncaught SyntaxError: Unexpected token <". I...
Read more >
Uncaught SyntaxError: Unexpected token "<" : r/reactjs - Reddit
The system tries to read a js file but it actually a HTML file the "<" token is the "<" from <!doctype html>....
Read more >
ReactJS: "Uncaught SyntaxError: Unexpected token " - YouTube
JavaScript : ReactJS : "Uncaught SyntaxError : Unexpected token " [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >
React function unexpected token expected
Btw, React: Unexpected token, expected “,” inside JSX [duplicate] ... passing an empty props and simple state interface to the component. map(child When...
Read more >
Uncaught SyntaxError: Unexpected token < in React - Hashnode
In the below line, you need to add type="text/babel" instead of text/javascript because it contains JSX which babel needs to transpile. Copy. < ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found