Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

bundle failed with moment.js #28

Closed
iron9light opened this issue Sep 26, 2016 · 3 comments
Closed

bundle failed with moment.js #28

iron9light opened this issue Sep 26, 2016 · 3 comments

Comments

@iron9light
Copy link

Got this error message:
bundle prod failed: Error: Cannot call a namespace ('moment')

+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @ionic/[email protected]
+-- @ngrx/[email protected]
+-- @ngrx/[email protected]
+-- @ngrx/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- [email protected]
+-- [email protected] invalid
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

@shlomiassaf
Copy link
Contributor

How can someone understand from this description, hi man open source give a little take some :) make an effort.

Anyway, I ran into you'r issue so I don't need much:
duplicate to #16

This semi-workaround will make it work on dev builds:

import moment from 'moment';

This will not work on production build, ngc will throw (it gets ignored on dev)

The core issue is with rollup build handling CommonJS modules.

When doing:

import * as moment from 'moment'

You satisfy typescript (and you write the correct import statement) but in the bundling process rollup will mis handle this package and make moment the module itself with a default property that is the moment function.

This is why you get the error.

In the "semi-workaround" you actually import using a statement rollup would expect so everything is fine (remember TS will output ES6 to rollup)

Now you can run in dev but you will see a TS error since you import incorrectly.

@danbucholtz
Copy link
Contributor

Hi @iron9light 😄 ,

This is a duplicate as @shlomiassaf noted. We are aware of the issue. We will fix it.

@shlomiassaf - no need to be rude to @iron9light. Please follow our code of conduct.

I'm going to close this issue and work off of the original.

Thanks,
Dan

@iron9light
Copy link
Author

@danbucholtz Thank you and this friendly community.
@shlomiassaf Thank you for your explain, and reminding. I will do more homework before next issue. Trust me, I do know what contribution mean.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants