Navigation Menu

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

Parcel: import works but require "moment is not a function" #4559

Closed
kenmorechalfant opened this issue Apr 13, 2018 · 4 comments
Closed

Parcel: import works but require "moment is not a function" #4559

kenmorechalfant opened this issue Apr 13, 2018 · 4 comments

Comments

@kenmorechalfant
Copy link

I've installed Moment via Yarn and in my client side script (which compiles with Parcel and Babel), if I do:

var moment = require('moment')

Then, whenever I try to use it I get the error moment is not a function. Which led me to this comment from an issue on a different project to try:

var moment = require('moment')['default']

Which appears to work fine, but I'm confused why it's necessary.

import moment from 'moment' on the other hand, works fine.

I just like to use require for consistency since I use Node.

@marwahaha
Copy link
Member

What version of moment are you using?

@kenmorechalfant
Copy link
Author

@marwahaha 2.22.1

@ichernev
Copy link
Contributor

@kenmorechalfant why is it necessary?

Well, after adding a non-backwards compatible module system in ES2016 I'm even surprised you can load moment at all. Go ask the smart guys behind the new standard. Is there a provision to make milions of lines of "old" ES5 code to "just work" -- no. Go figure!

We should have 2 (at least) targets, one for UMD (ES5) and one for ES2016 import / export crap. That would fix some of it.

@kenmorechalfant
Copy link
Author

@ichernev Haven't touched that project in a couple months but it wasn't "necessary". I just preferred using require() for consistency because it was what I was already using in Node and thus used it in Parcel and was having no issues with any other of the dozen scripts I was using. I would love to just do everything in ES2016 and use regular 'imports' but Node doesn't support them yet. I know that's not Parcel/Moment's problem, and I'm just a weekend warrior I don't know all the spaghetti required to support all these different module loaders.

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

3 participants