在antd4升级到5时候,因为版本5弃用 less,采用 CSS-in-JS,所以安装了@emotion/core和@emotion/styled
执行命令:
npm install @emotion/core @emotion/styled
但是运行后,页面报错:
The @emotion/core package has been renamed to @emotion/react. Please import it like this import { jsx } from '@emotion/react'
解决方案:
npm install @emotion/core@10.1.1
执行报错的话,在后面加上"--force"或者"--legacy-peer-deps"
f 或 --force:将强制 npm 获取远程资源,即使磁盘上存在本地副本也是如此。
–legacy-peer-deps:在安装时忽略所有 peerDependencies,采用 npm 版本 4 到版本 6 的样式。
如果在React应用程序中使用@emotion/core时出错:
添加包含
declare module '@emotion/core'
ts的新声明(.d.ts)文件