-
Notifications
You must be signed in to change notification settings - Fork 367
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
[Bug]: 使用react18和modern.js内置的react-helmet有类型冲突 #6389
Comments
typescript报错原因是cli工具生成项目后,安装的@types/react和@types/react-dom版本不对导致的,但是还是不能使用Fragment,我后面自己使用react-helmet-async就没问题。 |
怎么说呢,modern.js集成的好像都不是最新的,自己安装最新的,有些好像有兼容性问题,他们好像更加专注的还是 rsbuild ,能用就行了,毕竟优先于内部的工作,社区贡献出来用难听的话来说:就是拿来完善的。 |
可以贴下可复现的仓库,初始化的项目就是带 Helemt 的。你可以直接通过 https://modernjs.dev/apis/app/runtime/utility/head.html#%E6%9B%B4%E5%A4%9A%E7%94%A8%E6%B3%95 使用 helmet |
因为没有仓库,我不知道你提到的报错是在什么情况下出现的,但多半是由于多个 React Type 引起的,这是个常见的问题,如果你是 Monorepo 项目,更容易出现这样的问题。根本原因是 Helmet 依赖里 "@types/react": "*" 导致的。 |
没有这回事哈,Modern.js 一直处于频繁迭代的状态,如果有需要或者问题可以给我们提 issue 和 PR。 我们会看下 react-helmet-async,但 Meta 这块会同时考虑 React 19 和 React Router v7。 |
@alterass 期望是什么,@types/react和@types/react-dom 也需要使用 18.2.x 版本? |
是的,types的版本和react版本要一致,不然有些地方的tsx会报红色警号,比如react-router-dom的Outlet组件,虽然能运行,但是tsc代码检查报红色警告了。 |
版本信息
System:
OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor
Memory: 13.58 GB / 15.59 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
npmPackages:
@modern-js/app-tools: 2.60.3 => 2.60.3
@modern-js/runtime: 2.60.3 => 2.60.3
@modern-js/tsconfig: 2.60.3 => 2.60.3
问题详情
该bug源自于react-helmet,原因是不兼容 react18,按照社区的说法该项目已经停止维护了,社区给的建议是使用react-helmet-async。
原问题链接:nfl/react-helmet#646
vscode报错,只有将类型断言为any才不报类型错误。
不能使用Fragment,使用Fragment会导致无法正常运行。
多个head子元素,只能使用字符串的形式创建。
复现链接
nfl/react-helmet#646
复现步骤
The text was updated successfully, but these errors were encountered: