【问题标题】:Why is Ant Design throwing a Server Error when trying to use date-fns?为什么 Ant Design 在尝试使用 date-fns 时会抛出服务器错误?
【发布时间】:2022-01-08 10:01:51
【问题描述】:

使用 antd 文档中的 this guide 将 Moment.js 替换为 date-fns 后,我收到下一个服务器错误:

Screenshot of error.

SyntaxError: 不能在模块外使用 import 语句

我尝试过将'type': 'module' 添加到 package.json 并将'module': 'commonjs' 放入 tsconfig.json 以及许多其他方法,但似乎没有任何效果。

【问题讨论】:

    标签: typescript next.js antd date-fns


    【解决方案1】:

    知道了。解决方案是在文档中提供的导入中将'antd/es/...' 替换为'antd/lib/...',错误就消失了。

    Your DatePicker.tsx should look like this.

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      相关资源
      最近更新 更多