Side-effect locale import
Before
import "moment/locale/ja";After
import "mmntjs/locale-auto/ja";Use this when you want the old one-line import behavior to keep working during migration.
Migration
This page is for teams that need a realistic adoption path: evaluate first, replace in a small surface, compare behavior, then expand with confidence.
CLI Migration Tool
The mmntjs CLI automates the mechanical part of migration: scanning source
files, rewriting import paths, and generating a report to make rollout decisions visible.
# Scan first, then apply
mmntjs migrate --check # analyze
mmntjs migrate --mode=alias # npm alias (zero code change)
mmntjs migrate --apply --dry # preview rewrite
mmntjs migrate --apply # apply rewrite
mmntjs migrate --apply --fns # switch to fnsMigration Overview
The safest way to adopt mmntjs is to treat it as a compatibility bridge first and an optimization or modernization step second. Teams usually get better results by reducing the migration surface one ownership boundary at a time instead of attempting a global swap.
A good migration plan also makes room for the possibility that a few modules should stay on moment.js longer than others. That is not failure. It is a controlled rollout doing its job.
Locale Import Migration
Locale imports deserve an explicit check during migration because moment.js commonly relies on
side effects here. The mmntjs migration tool rewrites bare locale imports to
mmntjs/locale-auto/* so that import "moment/locale/ja" keeps the
same one-line behavior after migration.
Before
import "moment/locale/ja";After
import "mmntjs/locale-auto/ja";Use this when you want the old one-line import behavior to keep working during migration.
If you do not want side effects, keep using mmntjs/locale/* as pure data and
register only the locales you need with moment.locale(name, localeSpec).
import moment from "mmntjs";
import { jaLocale } from "mmntjs/locale/ja";
moment.locale("ja", jaLocale);Staged Rollout
Inventory current moment usage with mmntjs migrate --check. Identify timezone, locale, and parsing hotspots.
Optionally set npm alias with mmntjs migrate --mode=alias: zero code change, lets your build tool resolve moment → mmntjs at install time.
Run mmntjs migrate --apply to auto-rewrite imports. For full-only codebases, start with mmntjs (full compat). For lite-compatible code, switch directly to mmntjs/lite.
If your code only uses basic formatting/manipulation, mmntjs/fns is an option: standalone functions with tree-shakeable cost. Run mmntjs migrate --apply --fns --dry to preview.
Run compatibility checks and review known differences for the APIs your codebase uses. Compare production-like behavior, especially invalid dates, offsets, and custom parsing.
Replace imports in a low-risk module or service and run the existing test suite. Expand rollout module by module with ownership and rollback clarity.
Use the bridge period to guide new code toward modern date/time APIs, including Temporal where it fits.
Migration Approaches by Build Tool
mmntjs supports three migration patterns. Which one works best depends on your package manager and test runner.
| Approach | npm / yarn | pnpm | Jest / webpack | vitest | bun |
|---|---|---|---|---|---|
A: npm alias"moment": "npm:mmntjs" | ✅ | ✅* | ✅ | ✅* | ✅ |
B: Migration tool rewritemmntjs migrate --apply | ✅ | ✅ | ✅ | ✅ | ✅ |
C: Preload aliasModule._resolveFilename hook | ✅ | ✅* | ✅ | ✅* | ✅* |
* See notes below for details.
"moment": "link:../mmntjs/dist"
in the root package.json pnpm.overrides. The
file: and npm: protocols can interact poorly with pnpm's virtual
store in this setup.
pool: forks, forked workers may not inherit
the pnpm override resolution and can fail with Failed to resolve import "moment".
Switching to pool: threads resolves that failure mode.
vitest.resolve.alias with a 'moment' key does not reliably catch
the bare module specifier. Directly replacing node_modules/moment with a symlink
is overwritten by pnpm install.
mmntjs migrate --apply now rewrites
moment-timezone imports to mmntjs and adds a side-effect
import "mmntjs-timezone". Verify that the timezone package is installed
(npm install mmntjs-timezone) and test timezone-sensitive paths after migration.
Migration to Temporal
mmntjs report analyzes each file and estimates how many moment usages can be
expressed directly with Temporal APIs. That number is not a migration promise; it is a signal
for which modules are worth evaluating for a Temporal path first.
mmntjs itself is the bridge: keep legacy moment-shaped code stable on mmntjs, write new code against Temporal where the report shows a clean mapping, and retire the old surface on your schedule rather than on a migration deadline.
Concrete Rollout Examples
Good Fit
Use Caution
Testing Strategy
What Not To Rush
Risk Checklist
If your team can complete this checklist for one low-risk module first, the next expansion step becomes much more credible to reviewers and maintainers.
Minimal Comparison Set
Before expanding beyond the first module or service, keep a tiny comparison set that reflects the way your application actually uses dates. It does not need to be large. It needs to be representative.