Moment: webpack locale err

Created on 17 Aug 2017  ·  5Comments  ·  Source: moment/moment

Description of the Issue and Steps to Reproduce:

webpack config add:

  resolve: {
    alias: {
      vue$: 'vue/dist/vue.esm.js',
      moment: 'moment/src/moment'
    }
  }
<script>
import moment from 'moment'
moment.locale('zh-cn'); // pack error
</script>

Please include the values of all variables used.

Environment:

OSX Node.js 8.4.0

Both the browser and the OS are important to us, particularly if you have an unsual environment like an IOT application.

Other information that may be helpful:

  • The time zone setting of the machine the code is running on
  • The time and date at which the code was run
  • Other libraries in use (TypeScript, Immutable.js, etc)

If you are reporting an issue, please run the following code in the environment you are using and include the output:

console.log( (new Date()).toString())
console.log((new Date()).toLocaleString())
console.log( (new Date()).getTimezoneOffset())
console.log( navigator.userAgent)
console.log(moment.version)
console.log( (new Date()).toString())
Thu Aug 17 2017 17:09:27 GMT+0800 (CST)
console.log((new Date()).toLocaleString())
2017-8-17 17:09:27
console.log( (new Date()).getTimezoneOffset())
-480
console.log( navigator.userAgent)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3178.0 Safari/537.36
console.log(moment.version)
2.18.1

Ensure your issue is isolated to moment. Issues involving third party tools will be closed unless submitted by the tool's author/maintainer.

WARNING in ./node_modules/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in '/Users/willin/Documents/w2fs/coding-task/node_modules/moment/src/lib/locale'
 @ ./node_modules/moment/src/lib/locale/locales.js 55:12-39
 @ ./node_modules/moment/src/lib/locale/locale.js
 @ ./node_modules/moment/src/moment.js
 @ ./src/component/moment/index.js
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/router/timeline/tasks.vue
 @ ./src/router/timeline/tasks.vue
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/router/timeline/timeline.vue
 @ ./src/router/timeline/timeline.vue
 @ ./src/router/timeline/index.js
 @ ./src/router/index.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:3993 webpack/hot/dev-server ./src/main.js

Most helpful comment

webpack 3.6.0 + moment 2.19.0 still has the problem.

Seems like the proble is not fixed in latest release.....

All 5 comments

This was fixed in #4042 and should be fine in the next release. In the meantime the easiest reliable workaround for the the issue is to manaully change require('./locale/' + name) to require('moment/locale/' + name) in your node_modules/moment directory.

Hey just noticed on the change log page that this fix has not been included in a release yet, just wondering when the cuttable release is

webpack 3.6.0 + moment 2.19.0 still has the problem.

Seems like the proble is not fixed in latest release.....

Looks like the issue it's still there

Same problem here.
I have a project that's working on 4 computers. Another computer I am trying to set it up on throws the same error as described.
Webpack (2.2.1) and Moment (2.15.1) versions are the same everywhere. Node/Npm similar/same.

Was this page helpful?
0 / 5 - 0 ratings