How can I use external library like moment.js in my angular package?
See original GitHub issueType of Issue
- Bug Report
- Feature Request
Description
Let’s say I want to use momen.js library. When I do
import * as moment from 'moment';
ng-packgr will inline whole library to the bundle. How should I use it to act as peerDependecy so it would use packge installed in module where my library would be consumed?
By the way, despite the moment.js is inlined it seems it is not working when library is consumed by the target application 😦
I use same configuration as in https://github.com/dherges/ng-packaged
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to use moment.js library in angular 2 typescript app?
In the node_modules/angular2-moment will now be ".pipe.d.ts" files like calendar.pipe.d.ts, date-format.pipe.d.ts and many more.
Read more >How to Use JavaScript Libraries in Angular Project
Moment.js comes with a typing file called moment.d.ts . Now we can directly use the library by using import statement in the ts...
Read more >How do we replace Moment.js from our Angular Project
Steps to Replace Moment with Day.JS · Install the library · Import the typescript version of the library · Start copying/moving all functions...
Read more >Configure JavaScript libraries | WebStorm Documentation
On the Libraries page that opens, click Download and in the Download Library dialog that opens, select the required library, and click Download ......
Read more >Creating libraries - Angular
Use the Angular CLI and the npm package manager to build and publish your library as an npm package. Angular CLI uses a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you want to use moment both with Rollup (bundling using ng-packagr) and Webpack (if you use the library’s sources directly with Angualar CLI for example) you may find that the
import * as moment from 'moment'
import is not compatible with Angular CLI’s stack. For a compatible syntax for both bundlers, use the following:Currently using angular 6 library project and try to incorporate the moment.js in library project. Getting the same error - Cannot call a namespace (‘moment’)
Try the same solution which mention in above,
Added moment in ng-package.json file
“lib”: { “entryFile”: “src/public_api.ts”, “externals”: { “moment”: “moment” } }
However still getting the same error.