typescript 编译器警告“找不到模块:错误:无法解析‘./locale’”,因为我在我的反应应用程序中使用了 momentjs

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46706237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:57:50  来源:igfitidea点击:

Compiler warning "Module not found: Error: Can't resolve './locale'" since I use momentjs in my react app

reactjstypescriptnpmwebpackmomentjs

提问by gfjr

I get the following warning since I use moment.js in my application (npm 5.4.2, react 15.4, typescript 2.5.3, webpack 2.2.1, webpack-dev-server 2.4.1).

由于我在应用程序中使用了 moment.js(npm 5.4.2、react 15.4、typescript 2.5.3、webpack 2.2.1、webpack-dev-server 2.4.1),因此我收到以下警告。

In ./src/utils/commons.ts I use momentjs and it's working fine, but I get the warning.

在 ./src/utils/commons.ts 我使用 momentjs 并且它工作正常,但我收到警告。

Any help appreciated.

任何帮助表示赞赏。

WARNING in ./~/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in 'C:\myproject\node_modules\moment\src\lib\locale'
 @ ./~/moment/src/lib/locale/locales.js 65:16-60
 @ ./~/moment/src/lib/locale/locale.js
 @ ./~/moment/src/moment.js
 @ ./src/utils/commons.ts
 @ ./src/components/Login.tsx
 @ ./src/app.tsx
 @ ./src/index.tsx
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server react-hot-loader/patch webpack-dev-server/client?http://localhost:3000 webpack/hot/only-dev-server ./src/index.tsx
webpack: Compiled with warnings.

采纳答案by Andy Theos

This is a bug in Moment v2.19, due to changes in require: Issue on Github

这是 Moment v2.19 中的一个错误,由于需要更改: Github 上的问题

You can lock out 2.18.1 version in your package.json or apply fixes, mentioned in the link.

您可以在 package.json 中锁定 2.18.1 版本或应用链接中提到的修复程序。