【发布时间】:2021-10-15 04:43:06
【问题描述】:
我刚刚用create-react-app 设置了@emotion/react。 UI 工作正常,但在运行 jest 时,我收到此错误:
Cannot find module 'react' from '../node_modules/@emotion/react/dist/emotion-react.cjs.dev.js'
我试过了:
- 确保
react包在 package.json 中 - 删除
node-modules并重新运行yarn - 将文件指令更新为
/** @jsxImportSource @emotion/react */ - 安装
@testing-library/react - 安装
react-test-renderer - 安装
@emotion/jest
运气不好。知道为什么会发生这种情况吗?
仅从 Emotion 导入会引发此错误,但仅与 JSX 指令和导入语句一起使用。只有一个或另一个不会引发错误。将{ jsx } 更改为{ css } 也会导致问题不再重现。
/** @jsx jsx */
import { jsx } from "@emotion/react";
【问题讨论】: