Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot resolve 'file' or 'directory' ./locale #3872

Closed
ddjxie opened this issue Mar 28, 2017 · 17 comments
Closed

Cannot resolve 'file' or 'directory' ./locale #3872

ddjxie opened this issue Mar 28, 2017 · 17 comments

Comments

@ddjxie
Copy link

ddjxie commented Mar 28, 2017

Description of the Issue and Steps to Reproduce:
Node is unable to load moment's locales using Webpack because it cannot find the directory.

Error

WARNING in ./~/moment/min/moment-with-locales.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./locale in [project]/node_modules/moment/min
resolve file
resolve directory
  [project]/node_modules/moment/min/locale doesn't exist
 @ ./~/moment/min/moment-with-locales.js 271:16-43

Two temporary fixes that can resolve the issue locally (choose one)

  1. In [project]/node_modules/moment/min/moment-with-locales.js in the function "loadLocale", line 271, change
require('./locale/' + name);

to

require('../locale/' + name);
  1. Add a symbolic link to the directory
user@localhost:~/Workspace/[project]/node_modules/moment/min$ ln -s ../locale/

Environment:
Moment 2.18.1
Kubuntu 14.04 LTS 64-bit
Node.js 4.8.0 Argon LTS
Webpack 1.12.12

@icambron
Copy link
Member

icambron commented Apr 1, 2017

Hmm, yeah, that path clearly looks wrong; that tilda shouldn't be there. I don't use Webpack, so I'm not able to help, but in order to assist whoever does, can you share enough setup steps to help clarify whether this is a configuration issue or something wrong in the build?

@marwahaha
Copy link
Member

This seems related (but not exactly the same as) #2979

@bjackson
Copy link

@ddjxie Did you find a fix for this that didn't require altering the files in node_modules? I'm having this same issue.

@sanjay-k7r
Copy link

switching back to moment 2.18.1 also fixes the issue

@Domiii
Copy link

Domiii commented Oct 11, 2017

@kashalkar's answer is the real solution here. Go back a version and wait for the devs to finally fix this single character typo in the next release :)

@icambron
Copy link
Member

This is a bug reported against 2.18.1. 2.19.0 was released two days ago, so you must be experiencing something else.

@tim-white87
Copy link

I am getting this with 2.19.0, but not with 2.18.1.

@Domiii
Copy link

Domiii commented Oct 12, 2017

@icambron I had this on one system with 2.19.0. And like @kashalkar and @cecotw, going back to 2.18.1 fixes it. IIRC I did not have the issue on another system.

@ferencbalogh
Copy link

I tried with 2.18.1, 2.19.1, 2.19.2 but

Module not found: Error: Can't resolve './locale' in

@francisrod01
Copy link

The same error, I run the version ^2.19.2

@matveyok
Copy link

Same here, using 2.18.1 not helped. Any suggestions?

@francisrod01
Copy link

Maybe this solution can be help. #2979

@ferencbalogh
Copy link

ferencbalogh commented Dec 18, 2017 via email

@jamesdh
Copy link

jamesdh commented Dec 7, 2018

This appears to be the same issue as #4216 and can probably be closed in favor of that one (since it has a much more exhaustive history to it)

@HugoPoi
Copy link

HugoPoi commented Jan 2, 2019

I'm not sure this is a issue but how moment lib is construct, if you need to import in angular/typescript project you need to it like that
import * as Moment from 'moment';

@Hultner
Copy link

Hultner commented Jun 8, 2019

Had this problem in react native for web, managed to get around it by importing moment like this.

import moment from 'moment';
import 'moment/min/locales';

Fixed the web pack warnings for me and still works, other solutions didn't work in my case.

@marwahaha
Copy link
Member

marwahaha commented May 20, 2020

closing as duplicate of #2979

but as mentioned, #4216 has a lot of other info.

Sorry this is a long-standing issue for some Moment.js users.

There are various solutions depending on your use case throughout these comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests