Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
Why does <> give SyntaxError: Unexpected token in my React .js file

This is avery simple React jsx to js convertor project we're using to integrate React code into a legacy .aspx website. Eventually the who website will be written in React.

Whenever the Fragment shorthand <> is used the compiler returns a SyntaxError: Unexpected token.

Sample.js

import React from "react";

function Sample() {
    return (
        <>
            Hello world
        </>
    );
}
SyntaxError: src/Sample.js: Unexpected token (6:9)
  4 | function Sample() {
  5 |     return (
> 6 |         <>
    |          ^
  7 |             Hello world
  8 |         </>
  9 |     );

The project is using Babel 7.17.7 and babel-preset-react-app 3.1.2 which I think means the presets are set to recognize the shorthand <>.

This is the contents of the package.json file.

{
  "name": "react",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "jsx.bat"
  },
  "keywords": [],
  "author": "Russ Petersen (http://www.petesoft.com/)",
  "license": "ISC",
  "dependencies": {
  },
  "devDependencies": {
    "@babel/core": "^7.17.7",
    "babel-cli": "^6.26.0",
    "babel-preset-react-app": "^3.1.2",
    "react": "^17.0.2"
  }
}

I'm invoking the compile process with this command line.

jsx.bat

npx babel --watch src --out-dir . --presets react-app/prod

Yes we can use <React.Fragment> but <> has more style.

Any help you can give is appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Found the answer in "Uncaught SyntaxError: Cannot use import statement outside a module" after babel compilation

Changed command line (jsx.bat) to

npx babel --watch src --out-dir . --presets @babel/preset-react

and

package.json devDependencies to

"devDependencies": {
    "react": "^17.0.2",
    "@babel/cli": "^7.17.6",
    "@babel/core": "^7.17.7",
    "@babel/preset-react": "^7.16.7"
  }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda