moment: Cannot resolve 'file' or 'directory' ./locale

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I tried with 2.18.1, 2.19.1, 2.19.2 but

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

switching back to moment 2.18.1 also fixes the issue

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

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

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