Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Object(...) is not a function #28

Closed
burakkilic opened this issue Oct 10, 2017 · 12 comments
Closed

TypeError: Object(...) is not a function #28

burakkilic opened this issue Oct 10, 2017 · 12 comments

Comments

@burakkilic
Copy link

Hello,

I installed ngx-logger as in the manual. When I try to use it like in the code:

    this.logger.debug('Multiple', 'Argument', 'support');

I'm getting following warning:

WARNING in  ./node_modules/ngx-logger/index.js
134:15-18 "export 'utc' was not found in 'moment'

and in the developer console, I'm getting the following error:

ERROR TypeError: Object(...) is not a function
at NGXLogger.webpackJsonp.../../../../ngx-logger/index.js.NGXLogger._timestamp (index.js:134)

Is it because of moment.js? Or is it because of I'm using typescript?

@dbfannin
Copy link
Owner

dbfannin commented Oct 10, 2017

What version of NGX Logger is installed?
What version of angular is installed?
What version of moment is installed?

@burakkilic
Copy link
Author

I'm using Angular 4 and ngx-logger 0.2.7

@dbfannin
Copy link
Owner

What version of moment?

I might need you to try to reproduce this in a plunkr. If the versions seem ok. I'm not sure why it's having trouble finding utc().

@burakkilic
Copy link
Author

"moment": "2.19.0",

Angular is 4.2.4 by the way.

@IsNull
Copy link
Contributor

IsNull commented Oct 10, 2017

I can confirm this as well on angular 4.4.4.
Its possible that you need to update your angular cli to see the new warnings. @angular/cli @ 1.4.4

./node_modules/ngx-logger/index.js
134:15-18 "export 'utc' was not found in 'moment'
./node_modules/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in '***/webapp/node_modules/moment/src/lib/locale'
 @ ./node_modules/moment/src/lib/locale/locales.js 65:16-60
 @ ./node_modules/moment/src/lib/locale/locale.js
 @ ./node_modules/moment/src/moment.js
 @ ./node_modules/ngx-logger/index.js

What version of moment?

I might be wrong, but as far as I understand NPM, each package uses its own copy of all dependent libraries (unless you specify it as peer-dependency), so it will use the moment version you defined in the package.json.

The locale issue might indeed be a problem with moment itself, see issue moment/#2979

@dbfannin
Copy link
Owner

@burakkilic, this appears to be an issue with moment. I'm getting the same error when I install moment@2.19.0

For now, I've modified the packages.json to "moment": "~2.18.1" which will ignore changes to minor releases. Try installing ngx-logger@0.2.8 and that should solve your problem (you'll want to delete node_modules/moment first) and make sure you're not referencing version 2.19.0 anywhere else.

Let me know if this works for you.

@leo6104
Copy link
Contributor

leo6104 commented Oct 10, 2017

Hmm... @dbfannin how about remove moment.js dependency?

https://github.com/dbfannin/ngx-logger/blob/master/src/logger.service.ts#L75

I think _timestamp function can be replaced using new Date().toISOString()

moment.utc().format()  // "2017-10-10T13:17:40Z"
new Date().toISOString()  // "2017-10-10T13:17:40.291Z"

@dbfannin
Copy link
Owner

@IsNull, older versions of npm would install each dependency in a "node_modules" directory under the package. npm is now doing a flat approach in that in only installs sub dependencies if there already exists the package referenced, but it conflicts with the version needed by the package.

In other words. if "moment": "^2.18.1" is referenced in NGX Logger and moment@2.19.0 is installed, it will used moment@2.19.0 because it satisfies the requirement by the logger and there will not be a ngx-logger/node_modules/moment directory at all. the ^ also means that it will install and use the latest minor version released.

Now that I've modified "moment": "~2.18.1" only the latest patch version will be installed.

@dbfannin
Copy link
Owner

@leo6104, that's a very good point. There's very little benefit being pulled in from moment. especially since the only thing it is doing is formatting a date to the standard format.

@IsNull
Copy link
Contributor

IsNull commented Oct 10, 2017

@dbfannin I just was testing 0.2.8 and it resolves the issue. 👍

However, this confused me due to the above (wrong) assumptions I've made. Thanks to your explanation I get it now, thank you! I checked even my package lock, and it indeed showed that it switched from 2.19.x to 2.18.x.

@dbfannin
Copy link
Owner

@IsNull 👍

@leo6104, even though 0.2.8 resolved the issue, I do still agree we should remove moment as a dependency. I originally added it thinking we would get more use out of it, but that never happened. No need pulling in the entire moment library just for this. I've removed it and published ngx-logger@0.2.9 which uses the JavaScript Date() to create the formatted date.

@burakkilic
Copy link
Author

Yes, 0.2.8 resolved the issue. Thank you!

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

No branches or pull requests

4 participants