question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUILD Error when using momentjs

See original GitHub issue

Type 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
JoostKcommented, Nov 18, 2017

For a different workaround without the need to use moment-es6 nor allowSyntheticDefaultImports, please see https://github.com/dherges/ng-packagr/issues/163#issuecomment-345448834

2reactions
Nevergonnachangecommented, Nov 17, 2017

Thank you very much for your fast response!

import moment from 'moment-es6';

Works fine for me.

The

import moment from 'moment';
+
"allowSyntheticDefaultImports": true

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found