简体   繁体   English

为什么 Ant Design 在尝试使用 date-fns 时会引发服务器错误?

[英]Why is Ant Design throwing a Server Error when trying to use date-fns?

After replacing Moment.js with date-fns using this guide from the antd documentation I get the next server error:使用 antd 文档中的本指南将 Moment.js 替换为 date-fns 后,出现下一个服务器错误:

Screenshot of error.错误截图。

SyntaxError: Cannot use import statement outside a module SyntaxError: 不能在模块外使用 import 语句

I've tried things like adding 'type': 'module' to the package.json and putting 'module': 'commonjs' in tsconfig.json and many other things but none seem to work.我已经尝试过将'type': 'module'添加到 package.json 并将'module': 'commonjs'放入 tsconfig.Z466DEEC76ECDF5FCA6D38571F6324D5 中,但其他许多事情似乎都没有。

Got it.知道了。 The solution was to replace 'antd/es/...' with 'antd/lib/...' in the imports provided in the documentation and the error was gone.解决方案是在文档中提供的导入中将'antd/es/...'替换为'antd/lib/...'并且错误消失了。

Your DatePicker.tsx should look like this.您的 DatePicker.tsx 应该如下所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM