标签: theme-ui

如何使用打字稿和情感修复 Box 组件上的“属性‘颜色’类型不兼容”

Box我正在尝试在新项目上制作通用的反应组件。这将是所有其他组件的基础。我使用 styled-system、emotion 以及最终的 theme-ui 来处理所有组件的主题和样式。

我的根Box组件如下所示:

import styled from '@emotion/styled';
import {
  compose,
  space,
  layout,
  flexbox,
  border,
  position,
  color,
  SpaceProps,
  ColorProps,
  LayoutProps,
  FlexboxProps,
  BorderProps,
  PositionProps,
} from 'styled-system';

export type BoxProps = SpaceProps &
  ColorProps &
  LayoutProps &
  FlexboxProps &
  BorderProps &
  PositionProps;

export const Box = styled.div<BoxProps>(
  {
    boxSizing: 'border-box',
    minWidth: 0,
  },
  compose(space, color, layout, flexbox, border, position)
);
Run Code Online (Sandbox Code Playgroud)

我使用 styled-system 中的 styled 函数及其关联类型来创建一个接受空间、颜色、布局、flexbox、边框和位置属性的 Box 组件。

我收到的错误仅发生在color道具上。一旦我删除它,我就不会收到任何错误。

TS 错误为:

Type 'BoxProps' does not …
Run Code Online (Sandbox Code Playgroud)

emotion typescript styled-components theme-ui styled-system

5
推荐指数
1
解决办法
2954
查看次数

Next.js 12 与 theme-ui 一起使用时会中断,给出“code: 'ERR_REQUIRE_ESM'”

我正在使用Next.js 12 ,在使用theme-ui创建主题后弹出此错误

在此输入图像描述

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\fm-nextjs\node_modules\@mdx-js\react\index.js
require() of ES modules is not supported.
require() of E:\fm-nextjs\node_modules\@mdx-js\react\index.js from E:\fm-nextjs\node_modules\@theme-ui\mdx\dist\theme-ui-mdx.cjs.dev.js 
is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from E:\fm-nextjs\node_modules\@mdx-js\react\package.json.

    at Object.Module._extensions..js …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs es6-modules next.js theme-ui

5
推荐指数
1
解决办法
6万
查看次数