首页 > 解决方案 > 如何避免警告 `Module parse failed: Unexpected token` 来自 date-fns/locale

问题描述

date-fns在我的反应应用程序中使用。使用 Webpack(4) 和 babel(7) 构建应用程序时,会出现以下警告。

WARNING in ./node_modules/date-fns/locale/en/index.d.ts 1:8
Module parse failed: Unexpected token (1:8)
You may need an appropriate loader to handle this file type.
> declare module 'date-fns/locale/en' { }
| 
 @ ./node_modules/date-fns/locale sync ^\.\/.*$ ./en/index.d.ts

以下是我使用的代码块date-fns/locale

import fmt from 'date-fns/format';

export const format = (date, formatStr) =>
  fmt(date, formatStr, {
    locale: require(`date-fns/locale/en`),
  });

如何避免这个警告?

标签: webpackbabel-loaderbabel-polyfilldate-fns

解决方案


推荐阅读