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

Uncaught ReferenceError: _JSXStyle is not defined | >v3.3.2 | CRA + react-app-rewired + customize-cra + Production Build #711

Closed
eldarc opened this issue Mar 11, 2021 · 4 comments · Fixed by #724
Labels

Comments

@eldarc
Copy link

eldarc commented Mar 11, 2021

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

  • Using the latest styled-jsx version, or any version newer than v3.3.2 will produce a fatal error in the production build (when opened in the browser): _JSXStyle is not defined.
  • Dependencies: create-rect-app, react-app-rewired, customize-cra.
  • During development everything works as expected without any error.

If the current behavior is a bug, please provide the steps to reproduce and possibly a minimal demo or testcase in the form of a Next.js app, CodeSandbox URL or similar

  1. Create a new app with create-react-app.
  2. Install react-app-rewired and customize-cra
  3. Configure config-override.js:
const { override, useBabelRc } = require("customize-cra");

module.exports = override(
  useBabelRc("./.babelrc"),
);
  1. Configure .babelrc (same behavior when using the addBabelPlugin feature of customize-cra):
{
  "presets": ["babel-preset-react-app"],
  "plugins": [
    [
      "styled-jsx/babel",
      {
        "plugins": [
          [
            "@styled-jsx/plugin-sass",
            {
              "sassOptions": {
                "includePaths": ["./src/styles"]
              }
            }
          ]
        ]
      }
    ]
  ]
}

Same error happens for this .babelrc config:

{
  "presets": ["babel-preset-react-app"],
  "plugins": ["styled-jsx/babel"]
}

When there is no "plugins": ["styled-jsx/babel"] in .babelrc it works as expected, but then it's not possible to add plugins.

  1. yarn run build (react-app-rewired build) and serve -s build - or deploy to bucket/server
  2. Fatal error happens: Uncaught ReferenceError: _JSXStyle is not defined

What is the expected behavior?

styled-jsx should work in production the same as in development.

Environment (include versions)

  • OS: Any
  • Browser: Any
  • styled-jsx (version): >3.3.2

Did this work in previous versions?

It works with v3.3.2 but not in newer versions.

Could it be an issue with this? #684

Fix for now

  • Either do import _JSXStyle from "styled-jsx/style"; for each file.
  • Or hard-code 3.3.2 in package.json
@hpachy
Copy link

hpachy commented Mar 25, 2021

work for me :

{
  "presets": [
    [
      "next/babel",
      {
        "styled-jsx": {
          "plugins": ["@styled-jsx/plugin-sass"]
        }
      }
    ]
  ]
}

@bcomnes
Copy link

bcomnes commented Jul 7, 2021

Ran into this same error. Pinning to v3.3.2 seems to fix it again. It appears the transform no longer imports styled-jsx/style.

@masx200
Copy link

masx200 commented Aug 1, 2021

work for me :

{
  "presets": [
    [
      "next/babel",
      {
        "styled-jsx": {
          "plugins": ["@styled-jsx/plugin-sass"]
        }
      }
    ]
  ]
}

Thanks! This is the correct solution!

but why?

@github-actions
Copy link

github-actions bot commented Aug 2, 2021

🎉 This issue has been resolved in version 3.4.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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