__WEBPACK_IMPORTED_MODULE_4_moment__ is not a function when trying to use moment.js with typings
Please provide us with the following information:
- OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Ubuntu 14.04
- Versions. Please run
ng --version. If there's nothing outputted, please run in a Terminal:node --versionand paste the result here:
angular-cli: 1.0.0-beta.11-webpack.8
node: 6.3.1
os: linux x64
- Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. This is a project done from the start with angular cli.
- Install moment:
npm install moment --save
typings install dt~moment --global --save
Include in ts file:
import * as moment from 'moment'
and call any method:
moment().calendar()
- The log given by the failure. Normally this include a stack trace and some more information.
offers.service.ts:21 __WEBPACK_IMPORTED_MODULE_4_moment__ is not a function
OffersService.handleError @ offers.service.ts:21
ZoneDelegate.invoke @ zone.js:323
NgZoneImpl.inner.inner.fork.onInvoke @ ng_zone_impl.js:53
ZoneDelegate.invoke @ zone.js:322
Zone.run @ zone.js:216
(anonymous function) @ zone.js:571
ZoneDelegate.invokeTask @ zone.js:356
NgZoneImpl.inner.inner.fork.onInvokeTask @ ng_zone_impl.js:44
ZoneDelegate.invokeTask @ zone.js:355
Zone.runTask @ zone.js:256
drainMicroTaskQueue @ zone.js:474
ZoneTask.invoke @ zone.js:426
- Mention any other details that might be useful.
If I leave import * as moment from 'moment' in the component, the component wont run at all. If I remove it, the component works properly but I get client?93b6:49 [default] /home/alejo/projects/ng-backend/src/app/services/offers/offers.service.ts:37:31 Cannot find name 'moment'. when serving the app.
Thanks! We'll be in touch soon.
the webpack version doesn't use typings anymore, see the 3rd party library installation section of the README file:
npm install d3 --save
npm install @types/d3 --save-dev
@rodikal thank you, but that didn't work.
After doing
npm install moment --save
npm install @types/moment --save-dev
I still get the exact same error as before. What could I be doing wrong?
@alejoar I tested it again on a clean project, and for me it works. Did you start your project with angular-cli before the webpack version? Did you follow the upgrade manual?
FYI, this is how I created my project:
install/update angular-cli + create new project:
npm install -g angular-cli@webpack
ng new moment-test
in the new project, I installed moment:
cd moment-test
npm install --save moment
npm install --save-dev @types/moment
finally I adapted app.compoment.ts to use moment:
import { Component } from '@angular/core';
import * as moment from 'moment';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!' + moment().format();
}
finally, running ng serve and opening localhost:4200 and everything works fine.
I've uploaded the project here: https://github.com/rodikal/moment-test
I got the same error. I also need to have moment as a global dependency for fullcalendar so I did:
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/moment/moment.js",
"../node_modules/fullcalendar/dist/fullcalendar.min.js",
"../node_modules/fullcalendar-scheduler/dist/scheduler.min.js"
]
With moment in scripts I got __WEBPACK_IMPORTED_MODULE_4_moment__ is not a function. Without moment in scripts, fullcalendar does not work but moment works in *.ts file with import * as moment from 'moment';
EDIT:
angular-cli: 1.0.0-beta.11-webpack.9-4
node: 6.4.0
Closing in favor of https://github.com/angular/angular-cli/issues/2141 since it contains more detailed information on what appears to be the real problem.
No this command is not working guys, Please let me know what is the TypeError: __WEBPACK_IMPORTED_MODULE_2_react_apollo___default(...) is not a function While, this error occurs after the npm start. I had tried with so many commands which had shared with this github issues.... Then, I had rectify with the commands. Thanks in advance....
Hi Folks,
i am facing below error. Can anyone help me on this please. i am using intro.js version version 1.1.1.
ERROR TypeError: intro_js_intro_js__WEBPACK_IMPORTED_MODULE_3___default(...) is not a function
Thanks in advance.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.