Alanning roles_1.Roles.getRolesForUser is not a function


I try to add a role when an user just sing up

import {Roles} from  '@alanning/roles';

updateProfile(profile: Profile): void {
        console.log("Enter updateProfile");
        if (!this.userId) {
            throw new Meteor.Error('unauthorized','User must be logged-in to access a profile');

        check(profile, {
            firstname: nonEmptyString,
            lastname: nonEmptyString,
            birthday: nonEmptyString,
            email: nonEmptyString,
            phonenumber: nonEmptyString,

        Meteor.users.update(this.userId, {$set: {profile}});

        if(Roles.getRolesForUser(this.userId).length == 0)

But i having this error:

Exception while invoking method 'updateProfile' TypeError: roles_1.Roles.getRolesForUser is not a function
I20180502-15:28:42.731(4)?     at MethodInvocation.updateProfile (server/methods.ts:77:18)
I20180502-15:28:42.731(4)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1768:12)
I20180502-15:28:42.731(4)?     at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20180502-15:28:42.732(4)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1186:12)
I20180502-15:28:42.732(4)?     at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20180502-15:28:42.732(4)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1186:12)
I20180502-15:28:42.732(4)?     at Promise (packages/ddp-server/livedata_server.js:715:46)
I20180502-15:28:42.733(4)?     at new Promise (<anonymous>)
I20180502-15:28:42.733(4)?     at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20180502-15:28:42.733(4)?     at packages/ddp-server/livedata_server.js:559:43

Thanks in advance for your help.

To import meteor pacakges you need to use:

import { <module name> } from 'meteor/<package name>';

In the case of alanning:roles, the import statement should be:

import { Roles } from 'meteor/alanning:roles';
1 Like

Hi @coagmano,

I was trying to install alanning/role with npm.

Ok, i use import like you show me.
And I was installed

meteor add alanning:roles

And it’s work now.

But i don’t know why it’s have error with the npm package installation…

Anyway thanks a lot.

Basically Meteor supports two different package systems, npm packages, which we all know and love, and atmosphere packages (which is a Meteor specific package system)

Today, because of the widespread use of npm, most packages will be found on there.
However, many of the well used packages in the Meteor ecosystem pre-date the inclusion of npm support for Meteor and use Atmosphere.

Other packages, like alanning:roles extend Meteor functionality or packages and so are only possible because of the Meteor specific features that atmosphere packages have access to.

As a result (and as you discovered) alanning:roles doesn’t exist on npm

Hi @coagmano,

Sorry for my bad english.(Not sure if i can explain my issue or if i understand fine all that you said)

But it’s seems that alanning/roles exist on npm, here:
That just doesn’t work for me.

Huh, so there is!

It looks like the npm package version has a slightly different usage pattern (default exports, needs to be initialised against your database, etc), so I recommend removing it and using the Meteor/Atmosphere package instead.