-
Notifications
You must be signed in to change notification settings - Fork 236
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
moment is not a function - again #37
Comments
Hi, try to set |
There is no node_modules folder under ng2-datepicker. The only folder is src and, in it is components. I'm using version 0.8.0. |
Then correctly set |
It's correctly set. I am using version 2.14.1. Should I use a different version?
After I get the 200 for moment I get the error when I try to use the date picker. Here is the error: browser_adapter.js:84 TypeError: moment is not a function |
In my project I imported moment as: and then used it like this: I got the same error: 'moment is not a function'. Then I changed the import to: And it worked. ng2-datepicker uses this import: import * as moment from 'moment'; I don't see how this is the problem since everyone is not getting it. This stack overflow post led me to this: |
How do you set mappings in SystemJS configuration for moment? |
var config = { |
Try var map = {
'ng2-datepicker': 'node_modules/ng2-datepicker',
'moment': 'node_modules/moment'
}
var packages = {
'ng2-datepicker': { main: 'ng2-datepicker', defaultExtension: 'js' },
'moment': { main: 'moment', defaultExtension: 'js' }
} Something like that, I think. |
My node_modules is not hosted. The content is moved to lib/js/ by a gulp script I changed to this but still get the error.
} My only difference is the path the files. I have verified they are there and I see moment load in the network tab. |
I'll try to configure this with SystemJS and let you know. |
Is there a reason why you don't have import * as moment from '../../moment'; But that's not the right way though. |
This was the recommend way for a dotNet core project. They have a wwwroot folder for everything you want to host. By default, the npm packages install in node_modules outside of this hosted folder. I have several third party applications and they work - ng2-select, ng2-bs3-modal, ng2-file-upload, ng2-ckeditor, etc. I don't think I need to change the location of moment in the import. With the system.js config it can find it by just calling it moment. I have verified it with the network tab. Also, I have used moment (as a test) in my application with this import: "import moment from 'moment';" I changed your source to: |
No, that's not a solution. Still not sure if manually copying files from Not sure how Didn't checked if this is a reccomended way of a dotNet core project but I personally think this is wrong. |
I can look into changing it but they application has been in work for sometime. I'm not sure why the location of the files would matter if we are finding them. |
I changed my application to use the hosted node_modules as you suggested. It didn't help - I still have the problem. I reverted back to my normal structure. The runtime error is: "moment is not a function". My research indicates that when you import * a new object is created with the properties and functions and we want the original moment object like this. When I change the line to: import moment as moment from 'moment' the problem is resolved. Here is another directive with this problem and the same fix: Here is a stack overflow post: Any ideas? |
Hey @chambersDon, I just used this component a couple of days ago and everything works fine. Please check again the README and come back with questions if it still won't work. |
I have reviewed the readme and I don't see any differences from what I have done. What specifically do you think I missed?
It builds with no problem. Then at runtime I get: TypeError: moment is not a function. Also, I can't access your demo here: http://ng2-datepicker.jankuri.com |
I know, I am moving demos to other VPS. Please give me your SystemJS config and I'll take a look what can be done. |
(function (global) {
})(this); |
Hey @chambersDon, can you try new |
Closing this one out? |
yeah, I believe so since there's no response. Closing. |
I get an error at runtime that says: 'TypeError: moment is not a function'.
It's throwing the error on line 152: this.date = moment();.
I can see in the network tab that moment was downloaded successfully.
This is similar to issue #5 but I have followed those instruction and it's still not working.
I do not directly reference the node_modules files. Instead, I have a gulp file that moves what I need to the wwwroot folder (in a dotNet core application).
I don't get any compile errors with this import.
import {DatePicker} from 'ng2-datepicker';
I setup system.js so that ng2-datpicker points to ''ib/js/ng2-datepicker/src/components/ng2-datepicker' (note: this is the src - not the top level). At runtime it seems to find this JS but then crashes looking for moment.
I did the same for moment ('moment': 'lib/js/moment/moment') and I see the files are there but this is not working. It's finding moment so I'm not sure what the error is.
The text was updated successfully, but these errors were encountered: