Skip to content

__WEBPACK_IMPORTED_MODULE_4_moment__ is not a function when trying to use moment.js with typings #1974

Closed

Description

@alejoar

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    Ubuntu 14.04
  2. Versions. Please run ng --version. If there's nothing outputted, please run
    in a Terminal: node --version and paste the result here:
angular-cli: 1.0.0-beta.11-webpack.8
node: 6.3.1
os: linux x64
  1. 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.
  1. 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()

  1. 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
  1. 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.

Activity

  1. rodikal commented on Sep 6, 2016

    @rodikal

    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
    
  2. alejoar commented on Sep 7, 2016

    @alejoar
    Author

    @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?

  3. rodikal commented on Sep 8, 2016

    @rodikal

    @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

  4. MrChoclate commented on Sep 14, 2016

    @MrChoclate

    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
    
  5. filipesilva commented on Sep 21, 2016

    @filipesilva
    Contributor

    Closing in favor of #2141 since it contains more detailed information on what appears to be the real problem.

  6. Sabrinsulthana commented on Aug 14, 2018

    @Sabrinsulthana

    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....

  7. Vishnu4a7 commented on May 13, 2019

    @Vishnu4a7

    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.

  8. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  9. locked and limited conversation to collaborators on Sep 9, 2019
  10. added a commit that references this issue on Aug 29, 2023
    09207ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions