Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Luxon with Angular2?

I was looking for a library to use with Angular2 to handle dates and make diff/add, translations, etc ... I tried to install Luxon (http://moment.github.io/luxon/) by installing it via npm install --save-dev @types/luxon but it fails.

I always have errors like below when I compile my code:

Module not found: Error: Can't resolve 'luxon' in 'D:\App\src\app\planning-team' resolve 'luxon' in 'D:\App\src\app\planning-team' Parsed request is a module using description file: D:\App\package.json (relative path: ./src/app/planning-team) Field 'browser' doesn't contain a valid alias configuration

Does anyone already use Luxon with Angular ? How do you do ?

Thanks for your help. Regards, Mike

like image 795
GrooveRage Avatar asked Dec 28 '17 19:12

GrooveRage


1 Answers

This worked for me:

npm i luxon

npm i @types/luxon -D

Then your import:

import { DateTime } from 'luxon';

Now you can call const now = DateTime.local() in your Typescript.

like image 147
inorganik Avatar answered Oct 10 '22 12:10

inorganik