简体   繁体   中英

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:

Screenshot of error.

SyntaxError: Cannot use import statement outside a module

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.

Got it. The solution was to replace 'antd/es/...' with 'antd/lib/...' in the imports provided in the documentation and the error was gone.

Your DatePicker.tsx should look like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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