Skip to content

New jsx transform not applied when running tests after ejecting #10184

Closed
@celerytea

Description

@celerytea

Describe the bug

Getting "React is not defined" when running tests on react-scripts v4.0.1 after ejecting

Steps to reproduce

  1. Create a new project
  2. Eject
  3. Run a test

Actually I also got #6174 so I needed to remove node_modules and rerun yarn, but this is a different issue.

Analysis

Looking at

'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': isEjecting
? '<rootDir>/node_modules/babel-jest'
: resolve('config/jest/babelTransform.js'),

the unejected version runs babelTransform.js while the ejected version runs babel-jest directly, however babelTransform.js is where we set up the new jsx runtime.

Copying babelTransform.js and updating the "transform" key in package.json fixed this issue.

Alternatively updating package.json from

"babel": {
  "presets": [
    "react-app"
  ]
}

to

"babel": {
  "presets": [
    [
      "react-app",
      {
        "runtime": "automatic"
      }
    ]
  ]
}

would also fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions