Installation
Install with Bun, npm, or yarn
Requirements
- Node.js 18+, Deno or Bun
- Works in modern browsers and serverless environments
Usage Example
basic/installation-example.ts
import { addDays, type TimeZone, toISOString } from "datezone";
// Save timeZone, preferably in a user setting
const timeZone: TimeZone = "Asia/Tokyo";
const now = Date.now();
// Add 5 days in the Asia/Tokyo timeZone
const result = addDays(now, 5, timeZone);
// Format the result in ISO string format in the Asia/Tokyo timeZone
// (YYYY-MM-DDTHH:mm:ss.sss+09:00)
console.log(toISOString(result, timeZone));
ESM Compatibility & Module Resolution
Datezone is a modern ESM module that may require configuration changes in older projects. If you encounter import errors, this section will help you resolve them.
- Pure ESM module with
"type": "module"
in package.json - Uses the
exports
field instead of legacymain
/types
fields - No legacy fallback - relies entirely on the modern
exports
field
Common Installation Issues
If you see errors like these, your project needs modern module resolution:
Fix: Update Module Resolution
Update your tsconfig.json
to use modern module resolution:
Module Resolution Comparison
Resolution | Support | Notes |
---|---|---|
"node" (Legacy) | ❌ Won't work | Only understands main field, not exports |
"bundler" (Modern) | ✅ Recommended | Full exports field support, works with all bundlers |
"node16" /"nodenext" | ✅ Works | Node.js native ESM support |
For Older Projects
If you're working with a legacy codebase that cannot be upgraded:
- Update TypeScript to version 4.7+ for
"bundler"
support - Use a modern bundler (Vite, Webpack 5+, or Bun)
- Consider polyfill alternatives if stuck with very old tooling
Framework-Specific Notes
- Next.js: Requires version 13.1+ for proper ESM support
- Vite: Works out of the box with default configuration
- Webpack: Requires version 5+ with ESM support enabled
- Create React App: May need ejecting or switching to Vite