nextjs 开发的前端 next dev 没问题,但是 next build 怎么也过不了,报错很奇怪

339 天前
 xinmans
Failed to compile.

./pages/index.tsx:120:37
Type error: Property 'rev' is missing in type '{}' but required in type 'Pick<AntdIconProps, "default" | "id" | "data" | "title" | "colSpan" | "rowSpan" | "width" | "key" | "className" | "children" | "href" | "as" | "onMouseEnter" | "onTouchStart" | ... 349 more ... | "twoToneColor">'.

118 | }}
119 | >
> 120 | <Menu.Item key="0" icon={<HomeOutlined />}>
| ^
121 | 首页
122 | </Menu.Item>
123 | <Menu.Item key="1" icon={<SearchOutlined />}>
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.


      <Menu
          theme="dark"
          mode="inline"
          defaultSelectedKeys={["0"]}
          onClick={({ key }) => {
            setShowHome(key === "" || key === "0");
            setShowabc(key === "2");
            setShowabcd(key === "3");
            setShowSearch(key === "1");
            setShowabcde(key === "4");
            setShowAwsblogcn(key === "5");
          }}
          items={[
            {
              key: "0",
           

  icon: <HomeOutlined />,
              label: "首页",
            },
            {
              key: "1",
              icon: <SearchOutlined />,
              label: "搜索",
            },
            {
              key: "2",
              icon: <AppleOutlined />,
              label: "abc",
            },
            {
              key: "3",
              icon: <TwitterOutlined />,
              label: "abc",
            },
            {
              key: "4",
              icon: <AppleOutlined />,
              label: "abc",
            },
            {
              key: "5",
              icon: <TwitterOutlined />,
              label: "abc",
            },
          ]}
        ></Menu>
1390 次点击
所在节点    程序员
5 条回复
hhhanako
339 天前
dev 的时候不会对 typescript 检查,但是 build 的时候默认会。
你可以 1. 关闭 build 的时候对 tsc 检查,tsconfig 配置一下,但是不推荐
2.根据报错改好代码,看起来你似乎把 rev 打错了? 全局搜索一下
leokun
339 天前
HomeOutlined 组件不符合 icon 的签名吧
xinmans
338 天前
@leokun
@leokun import 了,antd 的标准 icon 组件,怎会不符合规范呢

import {
HomeOutlined,
AppleOutlined,
TwitterOutlined,
SearchOutlined,
CloudOutlined,
CloudServerOutlined,
MenuFoldOutlined,
MenuUnfoldOutlined,
} from "@ant-design/icons";
xinmans
338 天前
@hhhanako noEmit:ture 已经设置了,但还是报奇怪的错误
xinmans
338 天前
Fix by ChatGPT

这个错误显示,您在菜单项中使用了 AntdIcon 组件,但未传递必需的 "rev" 属性。AntdIconProps 接口规定了必须设置 rev 属性的对象。

要解决此问题,请确保将包含 "rev" 属性的对象传递给所有 AntdIcon 组件,并且已正确导入和声明所有类型。如果需要,您可以通过添加可选的 "rev" 属性来解决此特定错误:

```typescript
<Menu.Item key="0" icon={<AntdIcon type="home" style={{ fontSize: 16 }} rev={true} />}>
首页
</Menu.Item>
<Menu.Item key="1" icon={<AntdIcon type="search" style={{ fontSize: 16 }} rev={true} />}>
搜索
</Menu.Item>
<Menu.Item key="2" icon={<AntdIcon type="apple" style={{ fontSize: 16 }} rev={true} />}>
xx
</Menu.Item>
<Menu.Item key="3" icon={<AntdIcon type="twitter" style={{ fontSize: 16 }} rev={true} />}>
xx
</Menu.Item>
<Menu.Item key="4" icon={<AntdIcon type="cloud" style={{ fontSize: 16 }} rev={true} />}>
awsblog
</Menu.Item>
<Menu.Item key="5" icon={<AntdIcon type="cloud-server" style={{ fontSize: 16 }} rev={true} />}>
awsblogcn
</Menu.Item>
```

请注意,AntdIcon 组件的 type 属性接受字符串值,表示您要显示的图标类型。示例代码中使用的图标类型是示例代码中 Ant Design 提供的一些预定义图标类型。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/942707

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX