I have an Aurelia CLI project using TypeScript and I want to use date-fns npm package like below.
import { addHours, subDays } from 'date-fns';
but I got error messages when I build code.
$ au build
.
.
.
------- File not found or not accessible ------
| Location: /Users/pampers/dev/src/github.com/user/repo/add_days/index.js
| Requested by: /Users/pampers/dev/src/github.com/user/repo/src/feature/components/creation.js
| Is this a package? Make sure that it is configured in aurelia.json and that it is not a Node.js package
-----------------------------------------------
------- File not found or not accessible ------
| Location: /Users/pampers/dev/src/github.com/user/repo/add_hours/index.js
| Requested by: /Users/pampers/dev/src/github.com/user/repo/src/feature/components/creation.js
| Is this a package? Make sure that it is configured in aurelia.json and that it is not a Node.js package
-----------------------------------------------
------- File not found or not accessible ------
| Location: /Users/pampers/dev/src/github.com/user/repo/add_iso_years/index.js
| Requested by: /Users/pampers/dev/src/github.com/user/repo/src/feature/components/creation.js
| Is this a package? Make sure that it is configured in aurelia.json and that it is not a Node.js package
-----------------------------------------------
------- File not found or not accessible ------
| Location: /Users/pampers/dev/src/github.com/user/repo/add_milliseconds/index.js
| Requested by: /Users/pampers/dev/src/github.com/user/repo/src/feature/components/creation.js
| Is this a package? Make sure that it is configured in aurelia.json and that it is not a Node.js package
-----------------------------------------------
------- File not found or not accessible ------
| Location: /Users/pampers/dev/src/github.com/user/repo/add_minutes/index.js
| Requested by: /Users/pampers/dev/src/github.com/user/repo/src/feature/components/creation.js
| Is this a package? Make sure that it is configured in aurelia.json and that it is not a Node.js package
-----------------------------------------------
.
.
.
(more import errors)
Hi, @ViktorDimitrievski.
Thank you for your prompt reply.
I tried it, but date-fns package has no dist directory.
The structure of directories is like below.
@panchan9 the date-fns is currently not supported by cliβs default requirejs setup.
I could not figure out how to config date-fns to work. I worked on cli tracing code before, so you can take the answer as (almost) negative. But @JeroenVinke might help.
Anyway there is a way out. If you use cli + webpack, it definitely works. (au new proj, choose 3.Custom -> 3.Webpack).
Ohβ¦ Thatβs strange.
The version of date-fns is 1.29.0.
$ npm list -l date-fns
βββ date-fns@1.29.0
Modern JavaScript date utility library
git+https://github.com/date-fns/date-fns.git
https://github.com/date-fns/date-fns#readme
Would you mind installing the package locally with the following command? npm i date-fns
Thank you for your valueable information!
Iβm using requirejs as module loader, soβ¦ I hope that CLI supports libraries like date-fns.
One more thing. Could you tell me if a pattern of cli + systemjs works well?
Thanks.
Unfortunately, cli only uses systemjsβs AMD support. It means cli only uses systemjs as a requirejs implementation, it still uses exactly same tracing code to bundle all the js files.
I just ran through a setup with cli + systemjs + date-fns, I can confirm the behaviour is same as cli + requirejs.
This left you no choice but to use cli + webpack, unless you consider to switch to momentjs which is more popular than date-fns.
I am using momentjs and I have no complain. Anyway, I cannot judge date-fns since I have zero exp on it.
I have sent some details on gitter to cli maintainer @JeroenVinke for review. But he is a busy man, might need some days to respond.
Oh relly???
I donβt know that we all need to know everything, and also that we canβt make mistakes. With your reaction, you just discourage people to write posts on discourse.
Thanks for a such detailed explanation.
Okay, then Iβll use momentjs, because I just wanted to try using date-fns with Aurelia.
And thank you very much for sharing this issue with @JeroenVinke!