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

为君一笑 提交于 2020-01-03 20:05:40

问题


I have a problem with my application. I have a website. I use date-fns to show a formatted date based on the user language.

It works great, but I have updated date-fns and since then I have a warning. In my JavaScript code I use:

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

And with this, I can generate the right format like this:

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

It works, but I dislike this warning I get when webpack is building. Can you help me to understand what's wrong with my code? If it's in the webpack config or the include.

 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

回答1:


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



来源:https://stackoverflow.com/questions/53818219/webpack-warning-you-may-need-an-appropriate-loader-to-handle-this-file-type-da

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!