問題の説明と再現手順:
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>
使用するすべての変数の値を含めてください。
環境:
OSX Node.js 8.4.0
特にIOTアプリケーションのような異常な環境がある場合は、ブラウザとOSの両方が私たちにとって重要です。
役立つ可能性のあるその他の情報:
問題を報告している場合は、使用している環境で次のコードを実行し、出力を含めてください。
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
問題が瞬間的に分離されていることを確認してください。
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
これは#4042で修正され、次のリリースでは問題ないはずです。 それまでの間、この問題の最も簡単で信頼できる回避策は、node_modules / momentディレクトリでrequire('./locale/' + name)
をrequire('moment/locale/' + name)
に手動で変更することです。
変更ログページで、この修正がまだリリースに含まれていないことに気づきました。カット可能なリリースがいつリリースされるのか疑問に思っています。
webpack 3.6.0 + moment2.19.0にはまだ問題があります。
問題は最新のリリースでは修正されていないようです.....
それはまだそこにある問題のように見えます
ここでも同じ問題があります。
私は4台のコンピューターで動作しているプロジェクトを持っています。 私がセットアップしようとしている別のコンピューターは、説明したのと同じエラーをスローします。
Webpack(2.2.1)とMoment(2.15.1)のバージョンはどこでも同じです。 ノード/ Npm類似/同一。
最も参考になるコメント
webpack 3.6.0 + moment2.19.0にはまだ問題があります。
問題は最新のリリースでは修正されていないようです.....