BUILD Error when using momentjs
See original GitHub issueType of Issue
[X] Bug Report
[ ] Feature Request
Description
As a few people before me, I cannot run ng-packagr when using moment. I tried the suggested solutions in other issues but I cannot get it to work.
I added the following:
"lib": {
"externals": {
"moment": "moment"
}
}
When using import * as moment from ‘moment’; I get the following
BUILD ERROR
Cannot call a namespace ('moment')
Error: Cannot call a namespace ('moment')
When using import moment from ‘moment’
time-line/node_modules/moment/moment"' has no default export
How To Reproduce
Include moment into something and try to run ng-packagr
I uploaded a small example of my setup to GitHub where the issue is reproducible https://github.com/Nevergonnachange/moment-ng-packagr/tree/master/src
Expected Behaviour
Build passes
Version Information
ng-packagr: v1.6.0
node: v7.10.1
@angular: v5.0.0
rxjs: 5.5.2
zone.js: 0.8.18
moment: 2.19.2
Thank you very much in advance.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Error with moment js in angular 7 library - Stack Overflow
Error while trying to use the moment js in angular 7 library (Same is working in normal angular app). Steps to replicate: Create...
Read more >Docs - Moment.js
import moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022';. Note: In 2.4.0, the globally exported moment object was deprecated. It will be ...
Read more >Error when using moment.js - Microsoft Power BI Community
Solved: I am trying to use moment.js when creating a custom visual, but get the following error: Module not found: Error: Can't resolve...
Read more >Working with JavaScript Dates Using Moment.js - WebFX
js library. Then, to make sure it's working properly, we're going to instantiate a moment object and a JavaScript Date object, and then ......
Read more >Angular 2 Typescript building error with momentjs for moment ...
Check to make sure that the versions of Typescript and Moment that you have installed are compatible. I was running typescript v 1.8.x...
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
For a different workaround without the need to use
moment-es6
norallowSyntheticDefaultImports
, please see https://github.com/dherges/ng-packagr/issues/163#issuecomment-345448834Thank you very much for your fast response!
Works fine for me.
The
Adding a tsconfig.json with allowSyntheticDefaultImports set in the project root does not change anything. (as far as I understand I cannot change the tsconfig.json file for the ng-packagr).
I will for now use the moment-es6 workaround. It would still be nice to be able to get rid of it.
Thanks very much for you time and this awesome project.