Webpack 警告:您可能需要适当的加载程序来处理此文件类型 (date-nfs)

Webpack warning: You may need an appropriate loader to handle this file type (date-nfs)

我的申请有问题。我有一个网站。我使用 date-fns 来显示基于用户语言的格式化日期。

效果很好,但我更新了 date-fns,从那以后我收到了警告。在我的 JavaScript 代码中,我使用:

const locale = require(`date-fns/locale/${props.match.params.lang}`)

有了这个,我可以像这样生成正确的格式:

format(new Date(), 'D MMMM YYYY', { locale })

它有效,但我不喜欢在构建 webpack 时收到的警告。你能帮我理解我的代码有什么问题吗?如果它在 webpack 配置或包含。

 You may need an appropriate loader to handle this file type.
>frontend         | > declare module 'date-fns/locale/fr' { }
>frontend         | | 
>frontend         |  @ ./node_modules/date-fns/locale sync ^\.\/.*$ ./fr/index.d.ts
>frontend         |  @ ./assets/javascripts/features/weather/components/home-header.js
>frontend         |  @ ./assets/javascripts/features/weather/components/home.js
>frontend         |  @ ./assets/javascripts/features/weather/containers/home-container.js
>frontend         |  @ ./assets/javascripts/features/weather/containers/app.js
>frontend         |  @ ./assets/javascripts/features/weather/index.js
>frontend         |  @ ./assets/javascripts/app/router.js
>frontend         |  @ ./assets/javascripts/index.js
>frontend         |  @ multi (webpack)-dev-server/client?http://0.0.0.0:3000 ./assets/javascripts/index

试试这个: const locale = require(date-fns/locale/${props.match.params.lang}/index.js)