Registry / devops / moment-timezone-data-webpack-plugin

moment-timezone-data-webpack-plugin

JSON →
library1.5.1jsnpmunverified

This webpack plugin, `moment-timezone-data-webpack-plugin`, is designed to significantly reduce the bundle size of `moment-timezone` by selectively stripping unneeded time zone data during the webpack build process. As of version 1.5.1, it provides critical functionality for applications that use `moment-timezone` but don't require its entire historical and global dataset, which can be over 900KiB raw. The plugin actively processes the `moment-timezone` data module, allowing developers to specify date ranges (e.g., `startYear`, `endYear`), specific zones via regular expressions (`matchZones`), or countries (`matchCountries`). This addresses a common issue where `moment-timezone` includes all data by default in webpack builds, even if runtime configuration limits the data usage. The plugin is in active maintenance, with recent updates ensuring compatibility with NodeJS 18 and Webpack 5. It works complementarily with `moment-locales-webpack-plugin` for further bundle size optimizations.

npm install moment-timezone-data-webpack-plugin
INSTALL
IMPORT
SIG · MOMENT-TIMEZONE-DA
M
moment-timezone-data-webpack-plugin
devopsjavascriptv1.5.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
import MomentTimezoneDataPlugin from 'moment-timezone-data-webpack-plugin';
For `webpack.config.js` using CommonJS, the plugin is a default export requiring direct assignment.
default
import MomentTimezoneDataPlugin from 'moment-timezone-data-webpack-plugin';
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
For `webpack.config.mjs` or `webpack.config.ts` (with appropriate `module` resolution), the plugin is the default export.
MomentTimezoneDataPlugin
plugins: [new MomentTimezoneDataPlugin({ /* options */ })]
plugins: [MomentTimezoneDataPlugin({ /* options */ })]
Regardless of import style, the plugin must be instantiated with the `new` keyword within the `plugins` array of your webpack configuration.

This Webpack configuration demonstrates how to integrate `moment-timezone-data-webpack-plugin` to filter timezone data. It sets a date range (2020-2030), includes zones starting with 'Europe/', and all zones for Australia, significantly reducing the bundled `moment-timezone` data size.

import path from 'path'; import { Configuration } from 'webpack'; import MomentTimezoneDataPlugin from 'moment-timezone-data-webpack-plugin'; const config: Configuration = { mode: 'production', entry: './src/index.ts', // Assuming a simple entry point output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, module: { rules: [ { test: /\.ts$/, use: 'ts-loader', exclude: /node_modules/, }, ], }, resolve: { extensions: ['.ts', '.js'], }, plugins: [ // This example limits timezone data to specific years and only for zones matching 'Europe/' // and also includes all zones for 'AU' (Australia). // It's crucial to ensure these settings cover all needed timezones for your application. new MomentTimezoneDataPlugin({ startYear: 2020, endYear: 2030, matchZones: /Europe\//, // Only include zones matching 'Europe/' matchCountries: ['AU'], // Include all zones for Australia cacheDir: path.resolve(__dirname, '.moment-timezone-cache') // Optional: custom cache directory }), // Optionally, if also stripping locales // new MomentLocalesWebpackPlugin({ // localesToKeep: ['en', 'es'], // }), ], }; export default config;
Debug
Known issues
gotchaOver-aggressive data stripping can lead to runtime errors where `moment-timezone` reports missing data for dates or zones your application unexpectedly needs. Always thoroughly test your application after configuring this plugin.
fix
Carefully define `startYear`, `endYear`, `matchZones`, and `matchCountries` options. Consider a wider range or more zones if unsure, and use a staging environment for testing.
affects: >=1.0.0
breakingAs of v1.5.1, the plugin no longer officially tests against NodeJS 8 or 10. While no explicit code changes were made to break compatibility, usage on these End-of-Life Node.js versions is not guaranteed and unsupported.
fix
Upgrade your build environment to a supported Node.js version (e.g., Node.js 16 or newer) to ensure compatibility and receive official support.
affects: >=1.5.1
gotchaIncorrectly installing `moment-timezone` or `webpack` as non-peer dependencies, or incompatible versions, can cause build failures. The plugin relies on specific `webpack` APIs and `moment-timezone`'s internal structure.
fix
Ensure `moment-timezone` (`>=0.1.0`) and `webpack` (`4.x.x` or `5.x.x`) are installed as peer dependencies or compatible versions in your project.
affects: >=1.0.0
gotchaThe plugin requires `new` keyword when instantiating in `webpack.config.js`. Forgetting it will result in an error indicating the plugin is not a constructor.
fix
Always instantiate the plugin with `new MomentTimezoneDataPlugin({...})` in your webpack configuration file.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MomentTimezoneDataPlugin is not a constructor
The `new` keyword was omitted when instantiating the plugin in the webpack configuration.
fix
Change `plugins: [MomentTimezoneDataPlugin({...})]` to `plugins: [new MomentTimezoneDataPlugin({...})]`.
Module not found: Error: Can't resolve 'moment-timezone' in...
The `moment-timezone` package is not installed or not resolvable by webpack.
fix
Install `moment-timezone` using `npm install moment-timezone` or `yarn add moment-timezone`.
ERROR in [MomentTimezoneDataPlugin] Error: The timezone data for '...' is not available in the specified range...
Your application is attempting to use a timezone or date range that was stripped by the plugin configuration.
fix
Adjust the plugin options (`startYear`, `endYear`, `matchZones`, `matchCountries`) to include the necessary timezone data. Thoroughly test all time-related functionalities.
Webpack compilation error: Cannot read properties of undefined (reading 'compilation')
Often indicates an incompatibility between the plugin and the installed `webpack` version, or an issue with the webpack configuration itself where the plugin is not correctly initialized.
fix
Verify that your `webpack` version (`4.x.x` or `5.x.x`) is compatible with the plugin version. Ensure `webpack` and `moment-timezone-data-webpack-plugin` are correctly installed and configured in your `package.json` and `webpack.config.js`.
Upgrade
Version history
1.5.1latest on npm
Audit
Dependencies
moment-timezonerequiredRequired as the core library whose data is processed and optimized by this webpack plugin.
webpackrequiredServes as a webpack plugin, tightly integrated with webpack's build process and configuration. Supports webpack 4.x.x and 5.x.x.
Agent activity
2 hits · last 30 days
node
2
Resources
moment-timezone-data-webpack-plugin — npm install moment-timezone-data-webpack-plugin · libregistry