create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Support for the experimental syntax 'jsx' isn't currently enabled (45:5):

Open Tordek opened this issue 2 years ago • 41 comments

Steps to reproduce:

  • Create a new react App
  • Add https://github.com/Tordek/broken as a dependency (it's simply a project that contains a file with .js extension but uses jsx syntax.
  • Attempt to use the component in the app.

Result:

Failed to compile.

../broken/index.js
SyntaxError: D:\XXXX\broken\index.js: Support for the experimental syntax 'jsx' isn't currently enabled (4:13):

  2 |
  3 | export const Broken = () => {
> 4 |     return (<div></div>)
    |             ^
  5 | }

Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.

However the offered solution does not work because react-scripts/options/webpack.config.js disables the babelrc option.

On the other hand, this problem only seems to exist on Windows; it works fine in Linux.

Tordek avatar Dec 01 '21 16:12 Tordek

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Jan 08 '22 22:01 stale[bot]

Pinging to keep alive.

Tordek avatar Jan 09 '22 22:01 Tordek

Having the same issue on mac after I upgraded to Create React App, it's only happening while running the unit tests. But it's not happening because of a dependency, it happens within the app code.

FezVrasta avatar Jan 10 '22 13:01 FezVrasta

@Tordek @FezVrasta I have the same issue. Did you solve it?

okhanenko avatar Jan 26 '22 21:01 okhanenko

https://github.com/facebook/create-react-app/issues/11928 (includes a workaround I found)

FezVrasta avatar Jan 27 '22 07:01 FezVrasta

@FezVrasta Same issue on Ubuntu. I started a new project using npx to call Create React App. I tried importing a component from another local React project and got a similar error message.

olamideokunola avatar Feb 04 '22 09:02 olamideokunola

@Tordek Did you ever resolve this?

keithpickering avatar Mar 01 '22 01:03 keithpickering

No, I had to copy the components into the new project. Very much against DRY principle.

olamideokunola avatar Mar 01 '22 18:03 olamideokunola

@keithpickering no, the issue remains and can be reproduced as per the steps in the OP.

Tordek avatar Mar 02 '22 02:03 Tordek

I have the same issue

vitolipari avatar Mar 08 '22 13:03 vitolipari

i'm not that happy to join this club 🥇

Support for the experimental syntax 'jsx' isn't currently enabled after creating a TypeScript react project and installing an NPM package with react components created with JavaScript.

sarbull avatar Mar 10 '22 15:03 sarbull

If anyone missed it, I provided a workaround for this issue here https://github.com/facebook/create-react-app/issues/11928#issuecomment-1015175497

FezVrasta avatar Mar 10 '22 15:03 FezVrasta

Hi, is there a working solution for this? The workaround above does not work for me, I am using react-native-maps which uses fragments and triggers the error.

123epsilon avatar May 29 '22 04:05 123epsilon

I'm hitting this issue too, I'm however on Linux and am not using toMatchInlineSnapshot() which others have reported as being the issue.

import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";

import { Button } from "./Button";

describe("Button", () => {
    it("matches snapshot", () => {
        render(<Button onClick={function () {}} />);

        expect(screen.getByText("Click Me")).toBeInTheDocument();
    });
});

This is from a sample project https://github.com/IPWright83/pnpm-monorepo. I don't understand why this is happening now however, as it wasn't an issue when I set the project up originally. It's easy to reproduce in there by running:

npm install -g pnpm
pnpm install
pnpm test

I have managed to workaround it, but it's not nice. I have to, add the .babelrc file from https://github.com/facebook/create-react-app/issues/11928#issuecomment-1015175497 and I also need to add the following at the top of every test file:

/**
 * @jest-environment jsdom
 */

IPWright83 avatar Jun 07 '22 08:06 IPWright83

bump, same for Mac.

@FezVrasta it wasn't viable for me.

mjlomeli avatar Jun 09 '22 21:06 mjlomeli

Same issue happening for me when I try to add a folder with few components from "Project B" to my "Project A" as soft links using "mklink" command. None of the components in this folder has any dependency outside the folder. So their is no possibility that it is trying to refer something from "Project B" which is not available in "Project A" solution

I tried creating .babelrc and babal.config.js in different different formats and none worked. Finally I had to copy paste the files itself directly after which it is working.

shridhar-tl avatar Jun 18 '22 16:06 shridhar-tl

bump, still haven't been able to resolve this

gambowoa avatar Jun 24 '22 05:06 gambowoa

I'm having the same issue as well. I did create the create-react-app using typescript template, though.

ClydeDz avatar Jun 26 '22 10:06 ClydeDz

Same issue. create-react-app using typescript template.

rubencodes avatar Aug 31 '22 22:08 rubencodes

I am having the same issue (on Ubuntu) and @space-cadett 's answer I don't think is the solution because this is not about class properties.

kovkev avatar Sep 05 '22 18:09 kovkev

I fixed it by adding @babel/plugin-proposal-class-properties into webpack config plugin. The module section of my webpack.config.js looks like this

module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,        
        loader: "babel-loader",       
        options: {
          presets: ['@babel/preset-env',
                    '@babel/react',{
                    'plugins': ['@babel/plugin-proposal-class-properties']}]

        }
      },
    ],
  },

What has Class properties do with file extension ?

cristian-eriomenco avatar Sep 08 '22 15:09 cristian-eriomenco

Actually... that helped me. Odd.

kovkev avatar Sep 09 '22 02:09 kovkev

Getting the same error while importing files from a dependency package where files have the extension .js.

darekha avatar Oct 14 '22 12:10 darekha

Same error. Any update ?

hashaaan avatar Nov 06 '22 10:11 hashaaan

I'm also having this same issue. the workaround didn't work for me. Can someone who's a contributor please address this issue and offer example code solution

karkir0003 avatar Dec 17 '22 16:12 karkir0003

I am also hitting the same problem with gatsby. Any help is appreciated.

Compiled with problems:

ERROR in ./node_modules/gatsby/cache-dir/head/head-export-handler-for-browser.js

Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/stathis/src/anarres-frontend-v2/node_modules/gatsby/cache-dir/head/head-export-handler-for-browser.js: Support for the experimental syntax 'jsx' isn't currently enabled (113:9):

  111 |         // Note: In dev, we call onHeadRendered twice( in FireCallbackInEffect and after mutualution observer dectects initail render into hiddenRoot) this is for hot reloading
  112 |         // In Prod we only call onHeadRendered in FireCallbackInEffect to render to head
> 113 |         <FireCallbackInEffect callback={onHeadRendered}>
      |         ^
  114 |           <StaticQueryContext.Provider value={staticQueryResults}>
  115 |             <LocationProvider>
  116 |               <Head {...filterHeadProps(pageComponentProps)} />

Add @babel/preset-react (https://github.com/babel/babel/tree/main/packages/babel-preset-react) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx) to the 'plugins' section to enable parsing.
    at instantiate (/home/stathis/src/anarres-frontend-v2/node_modules/@babel/parser/lib/index.js:72:32)
...

stathismor avatar Dec 31 '22 20:12 stathismor

The JSX syntax extension is not currently enabled

script:/Users/vitou/My-doc/Vue/ecommerce/src/layouts/HeaderLayout.vue?id=0:7:8:
  7 │   icon: <tamplate>hi</tamplate>
    ╵         ^

The esbuild loader for this file is currently set to "js" but it must be set to "jsx" to be able to parse JSX syntax. You can use "loader: { '.js': 'jsx' }" to do that.

nheanvitou02 avatar Feb 09 '23 14:02 nheanvitou02

const routes = [{ id: 1, name: "Home", slu: "/", icon: hi }]

nheanvitou02 avatar Feb 09 '23 14:02 nheanvitou02

Still waiting for a solution on this issue

tblancog avatar Feb 15 '23 18:02 tblancog

Also experiencing the same issue

EricHasegawa avatar Feb 16 '23 21:02 EricHasegawa