Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

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

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.
like image 697
gfjr Avatar asked Oct 12 '17 09:10

gfjr


People also ask

Is it possible to import moment with locales in react application?

Application built with Create React App and using Moment 2.24.0, the following seems to be working fine: Instead of importing moment-with-locales directly. Alternatively, also possible to only import required locales:

How do I render a React component?

React components implement a render () method that takes input data and returns what to display. This example uses an XML-like syntax called JSX. Input data that is passed into the component can be accessed by render () via this.props.

How do I use JSX with react?

This example uses an XML-like syntax called JSX. Input data that is passed into the component can be accessed by render () via this.props. JSX is optional and not required to use React. Try the Babel REPL to see the raw JavaScript code produced by the JSX compilation step.


1 Answers

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

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

like image 174
Andy Theos Avatar answered Oct 19 '22 11:10

Andy Theos