我的应用程序有问题。我有一个网站。我使用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
答案 0 :(得分:0)
尝试一下:
const locale = require(date-fns/locale/${props.match.params.lang}/index.js
)