I just set up @emotion/react with create-react-app. The UI works fine, but when running jest, I'm getting this error:
Cannot find module 'react' from '../node_modules/@emotion/react/dist/emotion-react.cjs.dev.js'
I've tried:
- Make sure
reactpackage is in package.json - Delete
node-modulesand re-runyarn - Update file directive to
/** @jsxImportSource @emotion/react */ - Install
@testing-library/react - Install
react-test-renderer - Install
@emotion/jest
No luck. Any idea why this might be happening?
Just importing from Emotion throws this error, but only with the JSX directive and import statements together. Just one or the other does not throw the error. Changing { jsx } to { css } also causes the issue not to reproduce.
/** @jsx jsx */
import { jsx } from "@emotion/react";