标签: styled-jsx

迁移到 monorepo 结构后,Styled-jsx 打字稿错误。类型“DetailedHTMLProps”上不存在属性“jsx”

我在我的项目中使用 styled-jsx ,我只是将其迁移到 monorepo 结构,从那时起我一直遇到以下问题:

   Type '{ children: string; jsx: true; }' is not assignable to type 
   'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.
   Property 'jsx' does not exist on type 
   'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.ts(2322)
Run Code Online (Sandbox Code Playgroud)

每次我使用 style-jsx 的默认标签时,它都会出现在 jsx 属性下:

    <style jsx>
        {`...`}
    </style>
Run Code Online (Sandbox Code Playgroud)

我发现了有关此主题的已关闭问题,根据此链接,如果我手动将以下两行添加到interface HTMLAttributesin中,则可以解决此问题react/index.d.ts

    jsx?: boolean;
    global?: boolean;
Run Code Online (Sandbox Code Playgroud)

这实际上解决了问题,但我不想手动修改node_modules.

根据 vercel 中的这个已关闭问题,我应该能够通过简单地运行来解决这个问题yarn add -D @types/styled-jsx,但这不起作用。

使用 npm 而不是yarn 安装包也解决了这个问题,但我不想更改我正在使用的包管理器。此外,使用 npm 安装此一个包并使用 Yarn 安装其他包会导致应用程序崩溃。

我认为这可能是与纱线工作空间相关的提升问题styled-jsx,但添加

    "private": true,
    "nohoist":["**/styled-jsx","**/styled-jsx/**"]
Run Code Online (Sandbox Code Playgroud)

到我的根 package.json …

reactjs typescript-typings monorepo styled-jsx

12
推荐指数
2
解决办法
6209
查看次数

警告:收到非布尔属性 `jsx` 的 `true`。时代风格的 Jsx

我正在尝试将 styled-jsx 与一些代码一起使用。但是,无论我做什么,我似乎都会遇到错误

index.js:1437 Warning: Received `true` for a non-boolean attribute `jsx`.

If you want to write it to the DOM, pass a string instead: jsx="true" or jsx={value.toString()}.
    in style (at App.js:12)
    in div (at App.js:9)
    in Test (created by Route)
    in Route (at App.js:29)
    in Router (created by BrowserRouter)
    in BrowserRouter (at App.js:27)
    in App (at src/index.js:7)
Run Code Online (Sandbox Code Playgroud)

我尝试重新安装 node_modules,确保我的配置都很好,并测试了不同的版本。

我的 package.json,

{
  "name": "preview",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "contentful": "^7.4.1",
    "react": "^16.8.6",
    "react-dom": "^16.8.4",
    "react-router-dom": "^4.3.1",
    "react-scripts": …
Run Code Online (Sandbox Code Playgroud)

ecmascript-6 reactjs babeljs styled-jsx

5
推荐指数
3
解决办法
3147
查看次数