Git Product home page Git Product logo

timeago-react's Introduction

timeago-react

timeago-react is a simple react component used to format date with *** time ago statement. eg: '3 hours ago'.

The component based on timeago.js which is a simple javascript module.

  • Realtime render. Automatic release the resources.
  • Simple. Only 2kb.
  • Efficient. When the time is 3 hour ago, the interval will an hour (3600 * 1000 ms).
  • Locales supported.

npm build demo npm react supported npm

Install

npm install timeago-react

Usage

import * as React from 'react';
import TimeAgo from 'timeago-react'; // var TimeAgo = require('timeago-react');

<TimeAgo
  datetime={'2016-08-08 08:08:08'}
  locale='zh_CN'
/>

Component props

  • datetime (required, string / Date / timestamp)

The datetime to be formatted. can be datetime string, Date instance, or timestamp.

  • live (optional, boolean)

Live render, default is true.

  • className (optional, string)

The class of span. you can setting the css style of span by class name.

  • opts.relativeDate (optional, string / Date / timestamp)

The datetime to be calculated interval relative to.

  • opts.minInterval (optional, number in seconds)

The min interval in seconds to update the ** time ago string

  • locale (optional, string)

The locale language of statement, default is en. All supported locales here. If you want to use locale which is not zh_CN / en, you should import the locale before use it. As below:

import * as React from 'react';
import TimeAgo from 'timeago-react';
import * as timeago from 'timeago.js';

// import it first.
import vi from 'timeago.js/lib/lang/vi';

// register it.
timeago.register('vi', vi);

// then use it.
<TimeAgo
  datetime={'2016-08-08 08:08:08'}
  locale='vi'
/>
  • style (optional, object)

The style object to applied to the root element.

Props not documented above are applied to the root element.

LICENSE

MIT

timeago-react's People

Contributors

absk1317 avatar alanwei0 avatar boivie avatar hustcc avatar kerumen avatar kulla avatar nowakkamil avatar seungminio avatar spazzmarticus avatar szyablitsky avatar tommyku avatar wangweixuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

timeago-react's Issues

Using TimeAgo within code and outside render method

This is a question rather than issue.

I really love this plugin and work great. But i would also love to use this module outside the render method. So this my scenario, i'm using time ago during my initial page load, so inside the render method i have something like this:

<TimeAgo datetime={item.createdAt} title={new Date(item.createdAt.toString()).toLocalString('en-GB)} />

Above is used as part of an items collection and works great with no problem. Now each item is being updated via ajax. After a successful callback of the update i would like to update the TimeAgo on the dom via code on the fly, without reloading the whole component on the screen. I am trying something like this using reactElementToJSXString:

const divCreated = document.getElementById('someId') as HTMLDivElement; if(divCreated !== null) { divCreated.innertHTML = reactElementToJSXString(<TimeAgo datetime={item.createdAt} title={new Date(item.createdAt.toString()).toLocalString('en-GB)} />) }
While the above compiles, it just print the TimeAgo as html to the screen and its not processed by the plugin and converts to into readable friendly time.

My question is there a way to do this within a normal method? If not any alternative module that support what i'm trying to do. Almost all example i've seen are module component which works fine in render method not dynamically.

Thanks

README locale import snippet doesn't work out-of-the-box

The locale import snippet from the README doesn't work out-of-the-box.

import React from 'react';
import TimeAgo from 'timeago-react';
import * as timeago from 'timeago.js';

// import it first.
timeago.register('vi', require('timeago.js/locales/vi'));

// then use it.
<TimeAgo
  datetime={'2016-08-08 08:08:08'} 
  locale='vi'
/>

Module not found: Can't resolve 'timeago.js/locales/vi'

The following works without any issues whatsoever:

import React from 'react';
import TimeAgo from 'timeago-react';
import * as timeago from 'timeago.js';

// import it first.
import vi from 'timeago.js/lib/lang/vi';

// register it.
timeago.register('vi', vi);

// then use it.
<TimeAgo
  datetime={'2016-08-08 08:08:08'} 
  locale='vi'
/>

I'm using create-react-app. Please find the following excerpt from package.json:

"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-scripts": "3.1.1",
"timeago-react": "^3.0.0"

npm run build报错

环境:
node: v18.16.0
npm: 9.5.1

执行npm run build报错,如下:

[email protected] build
npm run build:cjs && npm run build:esm

[email protected] build:cjs
rimraf ./lib && tsc --module commonjs --outDir lib

node_modules/@types/babel__traverse/index.d.ts:321:9 - error TS1110: Type expected.

321 [k: ${string}|${string}]: VisitNode<S, Node>;
~~~

node_modules/@types/babel__traverse/index.d.ts:321:30 - error TS1005: ';' expected.

321 [k: ${string}|${string}]: VisitNode<S, Node>;
~

node_modules/@types/babel__traverse/index.d.ts:321:31 - error TS1128: Declaration or statement expected.

321 [k: ${string}|${string}]: VisitNode<S, Node>;
~

node_modules/@types/babel__traverse/index.d.ts:321:51 - error TS1005: '(' expected.

321 [k: ${string}|${string}]: VisitNode<S, Node>;
~

node_modules/@types/babel__traverse/index.d.ts:322:1 - error TS1128: Declaration or statement expected.

322 };
~

node_modules/@types/node/ts4.8/test.d.ts:831:34 - error TS1005: '?' expected.

831 : F extends abstract new (...args: any) => infer T
~~~

node_modules/@types/node/ts4.8/test.d.ts:832:17 - error TS1005: ':' expected.

832 ? T
~

node_modules/@types/node/ts4.8/test.d.ts:833:17 - error TS1005: ',' expected.

833 : unknown,
~

node_modules/@types/node/ts4.8/test.d.ts:836:34 - error TS1005: '?' expected.

836 : F extends abstract new (...args: infer Y) => any
~~~

node_modules/@types/node/ts4.8/test.d.ts:837:17 - error TS1005: ':' expected.

837 ? Y
~

node_modules/@types/node/ts4.8/test.d.ts:838:17 - error TS1005: ',' expected.

838 : unknown[],
~

node_modules/@types/node/ts4.8/test.d.ts:838:26 - error TS1005: ',' expected.

838 : unknown[],
~

node_modules/@types/node/ts4.8/test.d.ts:839:5 - error TS1109: Expression expected.

839 > {
~

node_modules/@types/node/ts4.8/test.d.ts:843:24 - error TS1005: ',' expected.

843 arguments: Args;
~

node_modules/@types/node/ts4.8/test.d.ts:847:35 - error TS1005: ',' expected.

847 error: unknown | undefined;
~

node_modules/@types/node/ts4.8/test.d.ts:853:39 - error TS1005: ',' expected.

853 result: ReturnType | undefined;
~

node_modules/@types/node/ts4.8/test.d.ts:857:21 - error TS1005: ',' expected.

857 stack: Error;
~

node_modules/@types/node/ts4.8/test.d.ts:862:19 - error TS1005: ',' expected.

862 target: F extends abstract new (...args: any) => any ? F : undefined;
~~~~~~~

node_modules/@types/node/ts4.8/test.d.ts:862:27 - error TS1005: ':' expected.

862 target: F extends abstract new (...args: any) => any ? F : undefined;
~~~~~~~~

node_modules/@types/node/ts4.8/test.d.ts:862:36 - error TS1005: ',' expected.

862 target: F extends abstract new (...args: any) => any ? F : undefined;
~~~

node_modules/@types/node/ts4.8/test.d.ts:862:55 - error TS1005: '{' expected.

862 target: F extends abstract new (...args: any) => any ? F : undefined;
~~

node_modules/@types/node/ts4.8/test.d.ts:862:64 - error TS1005: ',' expected.

862 target: F extends abstract new (...args: any) => any ? F : undefined;
~

node_modules/@types/node/ts4.8/test.d.ts:862:77 - error TS1005: ',' expected.

862 target: F extends abstract new (...args: any) => any ? F : undefined;
~

node_modules/@types/node/ts4.8/test.d.ts:866:22 - error TS1005: ',' expected.

866 this: unknown;

How do you use the options?

The opts minInterval and relativeDate are marked down as props in the documentation but there's no way to show how it's supposed to be used in the TimeAgo tag? Do you pass an opts object as a prop and use relativeDate and mininterval inside it or what? cause that didn't work

JSX element type 'TimeAgo' is not a constructor function for JSX elements.

I get an error on the TimeAgo component in SPFX TSX React:

Screenshot 2020-05-06 at 17 18 38

JSX element type 'TimeAgo' is not a constructor function for JSX elements.
  Type 'TimeAgo' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, and 2 more.

The return type of the function above is JSX.Element.

I think this issue is related to DefinitelyTyped/DefinitelyTyped#20544, but it should be able to bypass this.

timeago-react.js:96 Uncaught TypeError: this.timeagoInstance.cancel is not a function

version: "timeago-react": "^1.2.1"

timeago-react.js:96 Uncaught TypeError: this.timeagoInstance.cancel is not a function
    at TimeAgo.componentWillUnmount (timeago-react.js:96)
    at ReactCompositeComponent.js:409
    at measureLifeCyclePerf (ReactCompositeComponent.js:75)
    at ReactCompositeComponentWrapper.unmountComponent (ReactCompositeComponent.js:408)
    at Object.unmountComponent (ReactReconciler.js:79)
    at Object.unmountChildren (ReactChildReconciler.js:146)
    at ReactDOMComponent.unmountChildren (ReactMultiChild.js:373)
    at ReactDOMComponent.unmountComponent (ReactDOMComponent.js:980)
    at Object.unmountComponent (ReactReconciler.js:79)
    at ReactCompositeComponentWrapper.unmountComponent (ReactCompositeComponent.js:418)
componentWillUnmount @ timeago-react.js:96
(anonymous) @ ReactCompositeComponent.js:409
measureLifeCyclePerf @ ReactCompositeComponent.js:75
unmountComponent @ ReactCompositeComponent.js:408
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountChildren @ ReactChildReconciler.js:146
unmountChildren @ ReactMultiChild.js:373
unmountComponent @ ReactDOMComponent.js:980
unmountComponent @ ReactReconciler.js:79
unmountComponent @ ReactCompositeComponent.js:418
unmountComponent @ ReactReconciler.js:79
_updateRenderedComponent @ ReactCompositeComponent.js:757
_performComponentUpdate @ ReactCompositeComponent.js:724
updateComponent @ ReactCompositeComponent.js:645
receiveComponent @ ReactCompositeComponent.js:547
receiveComponent @ ReactReconciler.js:125
updateChildren @ ReactChildReconciler.js:109
_reconcilerUpdateChildren @ ReactMultiChild.js:208
_updateChildren @ ReactMultiChild.js:312
updateChildren @ ReactMultiChild.js:299
_updateDOMChildren @ ReactDOMComponent.js:936
updateComponent @ ReactDOMComponent.js:754
receiveComponent @ ReactDOMComponent.js:716
receiveComponent @ ReactReconciler.js:125
updateChildren @ ReactChildReconciler.js:109
_reconcilerUpdateChildren @ ReactMultiChild.js:208
_updateChildren @ ReactMultiChild.js:312
updateChildren @ ReactMultiChild.js:299
_updateDOMChildren @ ReactDOMComponent.js:936
updateComponent @ ReactDOMComponent.js:754
receiveComponent @ ReactDOMComponent.js:716
receiveComponent @ ReactReconciler.js:125
_updateRenderedComponent @ ReactCompositeComponent.js:754
_performComponentUpdate @ ReactCompositeComponent.js:724
updateComponent @ ReactCompositeComponent.js:645
receiveComponent @ ReactCompositeComponent.js:547
receiveComponent @ ReactReconciler.js:125
_updateRenderedComponent @ ReactCompositeComponent.js:754
_performComponentUpdate @ ReactCompositeComponent.js:724
updateComponent @ ReactCompositeComponent.js:645
receiveComponent @ ReactCompositeComponent.js:547
receiveComponent @ ReactReconciler.js:125
updateChildren @ ReactChildReconciler.js:109
_reconcilerUpdateChildren @ ReactMultiChild.js:208
_updateChildren @ ReactMultiChild.js:312
updateChildren @ ReactMultiChild.js:299
_updateDOMChildren @ ReactDOMComponent.js:936
updateComponent @ ReactDOMComponent.js:754
receiveComponent @ ReactDOMComponent.js:716
receiveComponent @ ReactReconciler.js:125
_updateRenderedComponent @ ReactCompositeComponent.js:754
_performComponentUpdate @ ReactCompositeComponent.js:724
updateComponent @ ReactCompositeComponent.js:645
receiveComponent @ ReactCompositeComponent.js:547
receiveComponent @ ReactReconciler.js:125
_updateRenderedComponent @ ReactCompositeComponent.js:754
_performComponentUpdate @ ReactCompositeComponent.js:724
updateComponent @ ReactCompositeComponent.js:645
receiveComponent @ ReactCompositeComponent.js:547
receiveComponent @ ReactReconciler.js:125
_updateRenderedComponent @ ReactCompositeComponent.js:754
_performComponentUpdate @ ReactCompositeComponent.js:724
updateComponent @ ReactCompositeComponent.js:645
performUpdateIfNecessary @ ReactCompositeComponent.js:561
performUpdateIfNecessary @ ReactReconciler.js:157
runBatchedUpdates @ ReactUpdates.js:150
perform @ Transaction.js:140
perform @ Transaction.js:140
perform @ ReactUpdates.js:89
flushBatchedUpdates @ ReactUpdates.js:172
closeAll @ Transaction.js:206
perform @ Transaction.js:153
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147

Incorrect time ago values

I have been using timeago-react for 6+ months and the value has been accurate as long as I can remember. This morning, I logged into my site and I am seeing "1 day ago" for timestamps on Friday (2-3 days ago). I have refreshed to make sure it wasn't some sort of stale value, but it persists. I created a few components with more recent timestamps and they look to be correct. I am also using the latest release: "timeago-react": "^3.0.4"

image

image

<div>
  <TimeAgo datetime={timestamp} className="small text-muted" />
</div>

React 18

Does this library support React 18? It shouldn't be too difficult to simply update the peerDependencies to allow React 18 (as I don't think a library as small as this one would need to change anything internally to support the changes introduced by React 18).

Missing dependency?

Uncaught Error: Module build failed: ReferenceError: Unknown plugin "transform-es3-member-expression-literals" specified in "/node_modules/timeago-react/.babelrc" at 0, attempted to resolve relative to "/node_modules/timeago-react"
at */node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:17

npm install babel-plugin-transform-es3-member-expression-literals will solve the problem

Requesting to change or add the feature to show 'a few second ago'

This is a request not an issue.
It looks weird to me that plugin showing an increasing "... second ago" text after 10 second.
Could you please change or add the feature so that it can show 'a few second ago' or something like this instead of increasing second counter.
Sorry for my English.

Warning: Unknown prop `live` on <time> tag. Remove this prop from the element.

Warning: Unknown prop `live` on <time> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in time (created by TimeAgo)
    in TimeAgo (at App.js:22)
    in div (at App.js:11)
    in App (at index.js:7)

my package.json

  "dependencies": {
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "timeago-react": "^1.2.0"
  }

Warning: checkPropTypes has been moved to a separate package.

Warning: checkPropTypes has been moved to a separate package. Accessing React.checkPropTypes is no longer supported and will be removed completely in React 16. Use the prop-types package on npm instead. (https://fb.me/migrating-from-react-proptypes)
transform[stderr]: Warning: React.createClass is no longer supported. Use a plain JavaScript class instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement. (https://fb.me/migrating-from-react-create-class)

Failed to parse source map

Run yarn start or yarn build output below warning:

WARNING in ./node_modules/timeago-react/esm/timeago-react.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago-react/src/timeago-react.tsx' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago-react/src/timeago-react.tsx'

WARNING in ./node_modules/timeago.js/esm/format.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/format.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/format.ts'
 @ ./node_modules/timeago.js/esm/index.js 10:0-34 10:0-34
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/index.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/index.ts'
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/lang/en_US.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/lang/en_US.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/lang/en_US.ts'
 @ ./node_modules/timeago.js/esm/index.js 5:0-33 8:18-23
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/lang/zh_CN.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/lang/zh_CN.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/lang/zh_CN.ts'
 @ ./node_modules/timeago.js/esm/index.js 6:0-33 9:18-23
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/realtime.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/realtime.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/realtime.ts'
 @ ./node_modules/timeago.js/esm/index.js 11:0-44 11:0-44 11:0-44
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/register.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/register.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/register.ts'
 @ ./node_modules/timeago.js/esm/index.js 7:0-38 8:0-8 9:0-8 12:0-20
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/utils/date.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/utils/date.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/utils/date.ts'
 @ ./node_modules/timeago.js/esm/format.js 1:0-51 12:12-19 14:9-19
 @ ./node_modules/timeago.js/esm/index.js 10:0-34 10:0-34
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

WARNING in ./node_modules/timeago.js/esm/utils/dom.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/timeago.js/src/utils/dom.ts' file: Error: ENOENT: no such file or directory, open 'node_modules/timeago.js/src/utils/dom.ts'
 @ ./node_modules/timeago.js/esm/realtime.js 1:0-71 19:8-18 31:2-12 41:18-28 57:14-30
 @ ./node_modules/timeago.js/esm/index.js 11:0-44 11:0-44 11:0-44
 @ ./node_modules/timeago-react/esm/timeago-react.js 51:0-52 113:4-10 118:6-12 124:4-10 143:16-22

Environment

webpack 5.65.0
source-map-loader 3.0.0
node v16.13.1

Does not work with React v17

See error when installing:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14.0 || ^15.0.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/timeago-react
npm ERR!   timeago-react@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

All locale files bundled?

I haven't tested yet, but seems
require('timeago.js/locales/' + this.props.locale));
will cause webpack to bundle all files under timeago.js/locales. (webpack has noway to know what value 'this.props.locale' could be, so it just includes all files in that folder)

Cannot find original docs, see this comment
webpack/webpack#38 (comment)

So code like this

  componentDidMount() {
    if (this.props.locale !== 'en' && this.props.locale !== 'zh_CN')
      timeago.register(this.props.locale, require('timeago.js/locales/' + this.props.locale));
      this.renderTimeAgo();
    },

is pretty much the same as require every thing statically.

The easiest solution shall be drop these lines, let user load locale files they need and pass to this component.

TimeAgo-react not using locale translated in timeago repo

Hello,
apparently the timeago-react is unable to find locales that are translated in the timeago repo
<TimeAgo datetime={article.createdAt} locale='zh_CN' />
works but all other languages:

<TimeAgo datetime={article.createdAt} locale='ar' />
<TimeAgo datetime={article.createdAt} locale='fr' />

fallback to english default.

Am i doing sth wrong ?

The format is not working

Hellow!

I putted the locale as "pt-BR" (portuguese - Brazil)
image

But it still printing in English
image

My default language of my operational system is English - United States

Are some another required thing to to?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.