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

Error with react-scripts test (jest): importSource cannot be set when runtime is classic #10987

Open
atvoid opened this issue May 19, 2021 · 1 comment

Comments

@atvoid
Copy link

atvoid commented May 19, 2021

Describe the bug

I'm using Jest with typescript 4.x and React 17 (Create React App 4).
The babel-jest transformer always throws error importSource cannot be set when runtime is classic
Because I'm using emotion css in my jsx, so I have to append the @jsxImportSource in the .tsx file, like:

/** @jsxImportSource @emotion/core */

I've tried overwrite the babel config like

  presets: [
    [
      require.resolve("babel-preset-react-app"),
      {
        runtime: "automatic",
      },
    ],
    [
      require.resolve("@babel/preset-react"),
      {
        runtime: "automatic",
        importSource: "@emotion/core",
      },
    ],
  ],
  plugins: [
    [
      require.resolve("@babel/plugin-transform-react-jsx"),
      {
        runtime: "automatic",
      },
    ],
  ],

it still doesn't work.

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

jestjs/jest#11394

Environment

Environment Info:

current version of create-react-app: 4.0.3
running from C:\Users\yuex\AppData\Roaming\npm-cache_npx\13392\node_modules\create-react-app

System:
OS: Windows 10 10.0.19043
CPU: (8) x64 Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Binaries:
Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: Not Found
Edge: Spartan (44.19041.964.0), Chromium (90.0.818.62)
Internet Explorer: 11.0.19041.1
npmPackages:
react: 17.0.2
react-dom: 17.0.2
react-scripts: 4.0.3 => 4.0.3
npmGlobalPackages:
create-react-app: Not Found

Steps to reproduce

  1. Set up a project by using Create React App 4, typescript 4.0 and @emotion/core
  2. append /** @jsxImportSource @emotion/core */ in the App.tsx file
    Then run npm run test

Expected behavior

Expect no error here.

Actual behavior

display below errors:
importSource cannot be set when runtime is classic

Reproducible demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

@stale
Copy link

stale bot commented Jun 26, 2021

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 Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant