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

MomentModule not defined #81

Closed
sg1705 opened this issue Oct 2, 2016 · 17 comments
Closed

MomentModule not defined #81

sg1705 opened this issue Oct 2, 2016 · 17 comments

Comments

@sg1705
Copy link

sg1705 commented Oct 2, 2016

I am using 1.0.0_beta.2 with Angular2 and Ionic 2 RC0 . When I try to build my application, I get the following error. Please help!

[10:46:26] rollup: Export 'MomentModule' is not defined by '/angular2-app/.tmp/app/app.module.ngfactory.js'

@sg1705 sg1705 changed the title Angular2 module not defined MomentModule not defined Oct 2, 2016
@urish
Copy link
Owner

urish commented Oct 2, 2016

Send like you are importing MomentModule from the wrong place?

On Oct 2, 2016 3:49 PM, "Saurabh Gupta" notifications@github.com wrote:

I am using 1.0.0_beta.2 with Angular2 and Ionic 2 RC0 . When I try to
build my application, I get the following error. Please help!

[10:46:26] rollup: Export 'MomentModule' is not defined by
'/angular2-app/.tmp/app/app.module.ngfactory.js'


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#81, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA2dnrUu7AJ3QM6RDSQiR2OfEbpRp_iAks5qv8RcgaJpZM4KMBuf
.

@sg1705
Copy link
Author

sg1705 commented Oct 2, 2016

I have tried importing from both

import { MomentModule } from 'angular2-moment/module';
and

import { MomentModule } from 'angular2-moment';

@rodriguesgm
Copy link

same problem for me

Error: Module my_app\node_modules\angular2-moment\index.js does not export MomentModule (imported by my_app.tmp\app\app.module.js)

@urish
Copy link
Owner

urish commented Oct 3, 2016

The following works perfectly for me - inside app.module.ts:

import { MomentModule  } from 'angular2-moment/module';

Then add MomentModule to the list of imports:

imports: [
    IonicModule.forRoot(MyApp),
    MomentModule
],

Can you please verify if you have the following file?

node_modules/angular2-moment/module.metadata.json

If it is missing, please remove the angular2-moment directory and reinstall it.

urish added a commit that referenced this issue Oct 3, 2016
@rodriguesgm
Copy link

ok, it worked for me.. thanks

@sg1705
Copy link
Author

sg1705 commented Oct 4, 2016

The file exists, however I am still getting this error. It's coming from rollup and when I build for production using enableProd()

@sg1705
Copy link
Author

sg1705 commented Oct 4, 2016

Here's the error that I get

[20:26:08] Error: Module ~myaapp/node_modules/angular2-moment/module.js does not export MomentModule (imported by ~myaapp/.tmp/app/app.module.js)

@TheMadBug
Copy link
Contributor

TheMadBug commented Oct 4, 2016

Hi guys, this kind of issue has hit a lot of projects now that Ionic 2 is using Rollup.
Rollup needs you to be explicit about what you are exporting, so index.ts

export * from './module';
export * from './CalendarPipe';
etc

Doesn't work, instead it needs to be

export { MomentModule } from './module';
export { CalendarPipe } from '/CalendarPipe';
etc

It's a pain to do, but it's a once off cost and it does allow projects to use libraries more efficiently by only including items that are used.

@sg1705
Copy link
Author

sg1705 commented Oct 4, 2016

@TheMadBug our pull requests crossed paths :-)

@TheMadBug
Copy link
Contributor

@sg1705 I just noticed, was writing a note about it but looks like I was too late to the party :)

@TheMadBug
Copy link
Contributor

If people need a temporary fix before either PR 86 or 87 is accepted, you can use:
"angular2-moment": "TheMadBug/angular2-moment#dist"
in your package.json

It's just a fork with the dependencies listed and then everything compiled and thrown into a github branch. Switch back to the proper npm once it gets updated.

@urish
Copy link
Owner

urish commented Oct 4, 2016

Fix published as 1.0.0-beta.3

@urish
Copy link
Owner

urish commented Oct 4, 2016

Thanks for everyone who contributed to this. I'm closing this issue - if this still happens with the newest beta, please open a new one.

@urish urish closed this as completed Oct 4, 2016
@candidosales
Copy link

I went back to version 1.0.0-beta.3, is included node_modules/angular2-moment/module.metadata.json file and still the error occurs in ionic2 project:

[17:32:15]  rollup: Export 'MomentModule' is not defined by '/Users/candidogomes/Documents/app-ios/.tmp/app/app.module.ngfactory.js'

[17:32:15]  Error: Module /Users/candidogomes/Documents/app-ios/node_modules/angular2-moment/module.js does not export MomentModule (imported by /Users/candidogomes/Documents/app-ios/.tmp/app/app.module.js)
    at Module.trace (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:7677:29)
    at ModuleScope.findDeclaration (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:7300:22)
    at Scope.findDeclaration (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5351:39)
    at Identifier.bind (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:6489:29)
    at /Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5151:50
    at ArrayExpression.eachChild (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5165:19)
    at ArrayExpression.bind (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5151:7)
    at /Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5151:50
    at Node.eachChild (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5168:5)
    at Node.bind (/Users/candidogomes/Documents/app-ios/node_modules/rollup/dist/rollup.js:5151:7)

Anyone can help me?

@sg1705
Copy link
Author

sg1705 commented Oct 6, 2016

Problem never went away for me.. I just gave up.

@TheMadBug
Copy link
Contributor

@candidosales @sg1705
Problem was fixed for me in 1.0.0-beta4, I never tried beta3.
Maybe beta 3 wasn't compiled correctly before publishing?

If you guys are still having trouble can you confirm the contents of
/node_modules/angular2-moment/index.js

"use strict";
var module_1 = require('./module');
exports.MomentModule = module_1.MomentModule;
var CalendarPipe_1 = require('./CalendarPipe');
exports.CalendarPipe = CalendarPipe_1.CalendarPipe;
etc

Cheers

@DeeM297
Copy link

DeeM297 commented Oct 23, 2016

Hi guys,

I decided to try angular2-moment with ionic 2 rc0 but not been able to make it work. Here's what I've done for the installation:

npm install --save angular2-moment
npm install @types/moment --save
npm install --save moment

I've changed the rollup.config.js file to add this line:

    commonjs({
        include: [  'node_modules/moment/**'
        ] })

And also added in tsconfig.json

    "types": [
      "moment"
    ]

In app.module.ts
I have added MomentModule in the @NgModule imports array and tried both
import {MomentModule} from 'angular2-moment/module'; (=> ngc error)
&
import {MomentModule} from 'angular2-moment'; (=> rollup error)
And getting two different errors:
ngc error

ngc failed: NGC encountered an error
Error: NGC encountered an error
at ChildProcess. (c:\Ionic\XXX\node_modules@ionic\app-scripts\dist\ngc.js:62:24)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at ChildProcess.cp.emit (c:\Ionic\XXX\node_modules\cross-spawn\lib\enoent.js:40:29)
at maybeClose (internal/child_process.js:821:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
Error running ionic app script "build": Error: NGC encountered an error

rollup error

rollup: Export 'MomentModule' is not defined by 'c:\Ionic\XXX.tmp\app\app.module.ngfactory.js'
bundle prod failed: Module c:\Ionic\XXX\node_modules\angular2-moment\index.js does not export MomentModule (imported by c:\Ionic\XXX.tmp\app\app.module.js)

I have re-installed angular2-moment a couple of times but not getting this file node_modules/angular2-moment/module.metadata.json

This is what I have in /node_modules/angular2-moment/index.js

"use strict";
var calendar_pipe_1 = require('./calendar.pipe');
exports.CalendarPipe = calendar_pipe_1.CalendarPipe;
var date_format_pipe_1 = require('./date-format.pipe');
exports.DateFormatPipe = date_format_pipe_1.DateFormatPipe;
var difference_pipe_1 = require('./difference.pipe');
exports.DifferencePipe = difference_pipe_1.DifferencePipe;
var duration_pipe_1 = require('./duration.pipe');
exports.DurationPipe = duration_pipe_1.DurationPipe;
var from_unix_pipe_1 = require('./from-unix.pipe');
exports.FromUnixPipe = from_unix_pipe_1.FromUnixPipe;
var moment_module_1 = require('./moment.module');
exports.MomentModule = moment_module_1.MomentModule;
var time_ago_pipe_1 = require('./time-ago.pipe');
exports.TimeAgoPipe = time_ago_pipe_1.TimeAgoPipe;
//# sourceMappingURL=index.js.map

Any ideas on how to make this work?

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

6 participants