Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tordek opened this issue Dec 1, 2021 · 45 comments
Open

Comments

@Tordek
Copy link

Tordek commented Dec 1, 2021

Steps to reproduce:

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.

@stale
Copy link

stale bot commented Jan 8, 2022

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 stale bot added the stale label Jan 8, 2022
@Tordek
Copy link
Author

Tordek commented Jan 9, 2022

Pinging to keep alive.

@stale stale bot removed the stale label Jan 9, 2022
@FezVrasta
Copy link
Contributor

FezVrasta commented Jan 10, 2022

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.

@okhanenko
Copy link

okhanenko commented Jan 26, 2022

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

@FezVrasta
Copy link
Contributor

FezVrasta commented Jan 27, 2022

#11928 (includes a workaround I found)

@olamideokunola
Copy link

@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.

@keithpickering
Copy link

@Tordek Did you ever resolve this?

@olamideokunola
Copy link

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

@Tordek
Copy link
Author

Tordek commented Mar 2, 2022

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

@vitolipari
Copy link

I have the same issue

@sarbull
Copy link

sarbull commented Mar 10, 2022

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.

@FezVrasta
Copy link
Contributor

If anyone missed it, I provided a workaround for this issue here #11928 (comment)

@123epsilon
Copy link

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.

@IPWright83
Copy link

IPWright83 commented Jun 7, 2022

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 #11928 (comment) and I also need to add the following at the top of every test file:

/**
 * @jest-environment jsdom
 */

@mjlomeli
Copy link

mjlomeli commented Jun 9, 2022

bump, same for Mac.

@FezVrasta it wasn't viable for me.

@shridhar-tl
Copy link

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.

@gambowoa
Copy link

bump, still haven't been able to resolve this

@ClydeDz
Copy link

ClydeDz commented Jun 26, 2022

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

@rubencodes
Copy link

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

@kovkev
Copy link

kovkev commented Sep 5, 2022

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.

@cristian-eriomenco
Copy link

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 ?

@kovkev
Copy link

kovkev commented Sep 9, 2022

Actually... that helped me. Odd.

@darekha
Copy link

darekha commented Oct 14, 2022

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

@hashaaan
Copy link

hashaaan commented Nov 6, 2022

Same error. Any update ?

@karkir0003
Copy link

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

@stathismor
Copy link

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

@nheanvitou02
Copy link

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
Copy link

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

@tblancog
Copy link

Still waiting for a solution on this issue

@EricHasegawa
Copy link

Also experiencing the same issue

@MiLandry
Copy link

Also having this problem.

@nikoloza
Copy link

nikoloza commented Mar 9, 2023

having the same problem with another React package linked in cra

@t-montes
Copy link

t-montes commented Apr 10, 2023

I had the same issue.
First check out that you have rendered correctly to an index.js file in a /dist folder, and then check that in the package.json file your main attribute is pointing to the right /dist file, for example:

{
  "name": "react-floating-mailbox",
  "version": "1.0.3",
  "description": "...",
  "main": "dist/index.js", // "dist/index.js" not just "index.js"
}

@Uttam146
Copy link

Same issue occur after trying so many solutions no result found

@Uttam146
Copy link

Uttam146 commented Jul 1, 2023

I have resolved this issue you can see my code from github https://github.com/Uttam146/uttam_rawat-popups/tree/master/src/package

@tammymogul
Copy link

Also having the same issue with another package.

@cassreinhart
Copy link

@Uttam146 This worked until babel couldn't parse a css file being imported. I added "type": "module" to package.json but still cannot parse.

@dtJon
Copy link

dtJon commented Aug 30, 2023

I am having this issue too. I cannot get google-map-react to work after two days of messing around with typescript configs and babel configs

@prodkt
Copy link

prodkt commented Oct 31, 2023

Same issue persists here. All this time and not anything definitive from CRA?

@sashafirsov
Copy link

solved by following jest docs

npm install --save-dev react-test-renderer

after which the Jest Runner VS Code plugin shown the functional Debug Test
image
The npm run test is functional as well.

@SimonWuensch-It-Studio-Rech

I solved the problem with a custom transformer -> https://jestjs.io/docs/tutorial-react#custom-transformers

@nheanvitou02
Copy link

nheanvitou02 commented Aug 28, 2024 via email

@amandakoster
Copy link

Hello, I am experiencing the same issue:
Support for the experimental syntax 'jsx' isn't currently enabled (80:13):
Am using
npx create-react-app my-app --template typescript
Next.js

I don't want to eject CRA and build out a babel config, bc that's why I like CRA.

Is there a fix for this or is CRA no longer supported?

@amandakoster
Copy link

I solved the problem with a custom transformer -> https://jestjs.io/docs/tutorial-react#custom-transformers

Can you share your config? I have tried a few the fixes here and they are not working for my app.
CRA with typescript/react-testing-lib + jest

@amandakoster
Copy link

I have resolved this issue you can see my code from github https://github.com/Uttam146/uttam_rawat-popups/tree/master/src/package

Did you use CRA? Did you eject? What are we looking at? Can you give more info? I would love to find a fix for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests