Registry / web-framework / vue-timeago

vue-timeago

JSON →
library5.1.3jsnpmunverified

The `vue-timeago` package provides a Vue.js component for displaying time in a human-readable "time ago" format, such as "5 minutes ago" or "2 days ago". The current stable version is 5.1.3, released in January 2021, indicating a slower release cadence, likely in a maintenance state for its existing feature set. It integrates with `date-fns` under the hood (since version 5.0.0) for precise date calculations and extensive locale support, which differentiates it from prior versions (like v3 and v4) that were much smaller but potentially less robust. It functions as a Vue plugin, exposing a `<timeago>` component that accepts a `datetime` prop and offers auto-updating capabilities, custom locales, and converter functions. While it leverages `date-fns` for its core logic, this dependency means a larger bundle size compared to its predecessors. It is primarily designed for Vue 2 applications, with dedicated alternatives available for Vue 3.

npm install vue-timeago
INSTALL
IMPORT
SIG · VUE-TIMEAGO
V
vue-timeago
web-frameworkjavascriptv5.1.3
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.

VueTimeago
import VueTimeago from 'vue-timeago'
const VueTimeago = require('vue-timeago')
This is the primary way to import the plugin for global registration with `Vue.use()`.
Locale (date-fns)
import zhCN from 'date-fns/locale/zh_cn'
const zhCN = require('date-fns/locale/zh_cn')
The README examples show CommonJS `require` for date-fns locales. In modern ESM or TypeScript projects, use `import` for tree-shaking and consistency.
Timeago (component usage)
<template><timeago :datetime="myDate"></timeago></template>
After registering the plugin globally, the `<timeago>` component is available in your templates.

This quickstart demonstrates how to install `vue-timeago` as a Vue plugin, register custom `date-fns` locales, and use the `<timeago>` component with various props, including auto-update and custom locales, for both past and future dates.

import Vue from 'vue' import VueTimeago from 'vue-timeago' import zhCNLocale from 'date-fns/locale/zh_cn' import jaLocale from 'date-fns/locale/ja' // Register the plugin globally Vue.use(VueTimeago, { name: 'Timeago', // Component name locale: 'en', // Default locale locales: { 'zh-CN': zhCNLocale, ja: jaLocale } }) // Example Vue component usage export default { name: 'App', data() { return { // Use a past date for a clear 'time ago' display pastTime: new Date(2023, 10, 15, 10, 30, 0), // November 15, 2023, 10:30:00 // Use a future date to show 'in X time' futureTime: new Date(Date.now() + 1000 * 60 * 60 * 24 * 5) // 5 days from now } }, template: ` <div id="app"> <h1>Time Ago Examples</h1> <p>Simple usage: <timeago :datetime="pastTime"></timeago></p> <p>Auto-update every 30 seconds: <timeago :datetime="pastTime" :auto-update="30"></timeago></p> <p>Custom locale (Chinese): <timeago :datetime="pastTime" locale="zh-CN"></timeago></p> <p>Future date: <timeago :datetime="futureTime"></timeago></p> </div> ` }
Debug
Known issues
breakingVersion 5.x introduced `date-fns` as its underlying date utility, which significantly increased bundle size (from ~700 bytes gzipped in v4 to ~2.8kB gzipped in v5). This change also alters the available `converterOptions` as they now map to `date-fns` options.
fix
Review bundle size impact and, if critical, consider sticking to older `vue-timeago` versions (e.g., v4) or alternative lightweight solutions if `date-fns`'s features are not fully utilized. Adjust `converterOptions` if migrating from v4.
affects: >=5.0.0
gotcha`vue-timeago` is designed for Vue 2 applications. It is not directly compatible with Vue 3 due to changes in Vue's plugin API and component registration. Attempting to use it in a Vue 3 project will result in errors related to `Vue.use()` or component instantiation.
fix
For Vue 3 projects, use `vue-timeago3` or `@vueuse/core`'s `useTimeAgo` composable, which are built specifically for Vue 3's composition API or new plugin system.
affects: >=5.0.0
gotchaThe documentation's locale examples use CommonJS `require('date-fns/locale/...')`. In modern ESM-only or TypeScript projects without specific bundler configurations for CJS, directly using `require` might lead to import errors. Ensure your build setup correctly handles CJS modules or use ESM `import` statements.
fix
Replace `require('date-fns/locale/...')` with `import localeName from 'date-fns/locale/locale_name'` and configure your bundler (e.g., Webpack, Vite) to handle `date-fns` imports correctly for ESM environments. Most bundlers will handle `date-fns` CJS builds automatically, but explicit ESM imports are preferred.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'use')
Vue is not globally available or correctly imported before `Vue.use(VueTimeago)` is called. This often happens in module-based setups where Vue is not exposed globally by default, or when using Vue 3's new API.
fix
Ensure `import Vue from 'vue'` is present and Vue is initialized before `Vue.use()`. If using Vue 3, `vue-timeago` is incompatible; use `vue-timeago3` instead.
Error: Cannot find module 'date-fns/locale/...' or similar module resolution error for date-fns.
The `date-fns` package, or its specific locale files, are not installed or are not correctly resolved by your bundler, especially when using `require()` syntax in an ESM project.
fix
Ensure `date-fns` is installed (`npm install date-fns` or `yarn add date-fns`). Verify your bundler configuration for module resolution, and consider using ESM `import` statements for `date-fns` locales instead of `require()`.
Invalid Date displayed or incorrect 'time ago' calculation.
The `datetime` prop received by the `<timeago>` component is not a valid Date object, a parsable date string, or a number (timestamp).
fix
Ensure the `datetime` prop is a valid JavaScript `Date` object, a string parseable by `Date.parse()` (e.g., ISO 8601 format), or a Unix timestamp (number of milliseconds since epoch).
Upgrade
Version history
5.1.3latest on npm
Audit
Dependencies
date-fnsrequiredUsed internally by the default converter for date formatting and localization. Required if providing custom locales or using the default converter's advanced options.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vue-timeago — npm install vue-timeago · libregistry