Unknown provider: Meteor.userId

Hi,

I’m currently working on a Meteor application that uses AngularJS and ionic as the front-end component, which I’m not familiar with. My goal is to migrate it from Meteor 1.2 to 1.8. Now, I’m at a stage to migrate my application from 1.6.1.4 to 1.7.0.5. It works fine in Meteor 1.6.1.4, but the routing stops working when I updated Meteor to 1.7. There is no error at compile time and runtime. However, if I debug my application (either in chrome or vscode) and allow all exceptions to be captured, whenever I try to navigate to other routes, an exception occurs as shown below:

Exception has occurred: Error
Error: [$injector:unpr] Unknown provider: Meteor.userId(Provider <- Meteor.userId(
http://errors.angularjs.org/1.4.8/$injector/unpr?p0=Meteor.userId(Provider%20%3C-%20Meteor.userId(
    at http://localhost:3000/packages/angular_angular.js?hash=73c8bcda9a1c9e883cf9771937278c968a815c22:93:12
    at http://localhost:3000/packages/angular_angular.js?hash=73c8bcda9a1c9e883cf9771937278c968a815c22:4359:19
    at Object.getService [as get] (http://localhost:3000/packages/angular_angular.js?hash=73c8bcda9a1c9e883cf9771937278c968a815c22:4507:39)
    at http://localhost:3000/packages/angular_angular.js?hash=73c8bcda9a1c9e883cf9771937278c968a815c22:4364:45
    at getService (http://localhost:3000/packages/angular_angular.js?hash=73c8bcda9a1c9e883cf9771937278c968a815c22:4507:39)
    at Object.invoke (http://localhost:3000/packages/angular_angular.js?hash=73c8bcda9a1c9e883cf9771937278c968a815c22:4539:13)
    at proceed (http://localhost:3000/packages/angularui_angular-ui-router.js?hash=79e1d21fcfb01f251c0f5481c7058e2896f6bc80:507:42)
    at invoke (http://localhost:3000/packages/angularui_angular-ui-router.js?hash=79e1d21fcfb01f251c0f5481c7058e2896f6bc80:503:26)
    at http://localhost:3000/packages/angularui_angular-ui-router.js?hash=79e1d21fcfb01f251c0f5481c7058e2896f6bc80:482:14
    at $Resolve.resolve (http://localhost:3000/packages/angularui_angular-ui-router.js?hash=79e1d21fcfb01f251c0f5481c7058e2896f6bc80:586:34)

Here is my Meteor package info:

accounts-base@1.4.2
accounts-password@1.5.1
allow-deny@1.1.0
angular-templates@1.0.3
angular-templates-runtime@0.0.1
angular:angular@1.4.8
angular:angular-animate@1.4.8
angular:angular-sanitize@1.4.8
angularui:angular-ui-router@0.2.15
autoupdate@1.4.0
babel-compiler@7.1.1
babel-runtime@1.2.4_1
base64@1.0.11
binary-heap@1.0.10
blaze@2.3.2
blaze-tools@1.0.10
boilerplate-generator@1.5.0
caching-compiler@1.1.12
caching-html-compiler@1.0.6
callback-hook@1.1.0
check@1.3.1
ddp@1.4.0
ddp-client@2.3.2
ddp-common@1.4.0
ddp-rate-limiter@1.0.7
ddp-server@2.2.0
deps@1.0.12
diff-sequence@1.1.0
driftyco:ionic@1.2.4
dynamic-import@0.4.2
ecmascript@0.11.1
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.7.1
ecmascript-runtime-server@0.7.0
ejson@1.1.0
email@1.2.3
es5-shim@4.8.0
geojson-utils@1.0.10
hot-code-push@1.0.4
html-tools@1.0.11
htmljs@1.0.11
http@1.4.1
id-map@1.1.0
jquery@1.11.10
launch-screen@1.1.1
livedata@1.0.18
localstorage@1.2.0
logging@1.1.20
maazalik:highcharts@0.4.0
meteor@1.9.0
meteor-base@1.4.0
minifier-css@1.3.1
minifier-js@2.3.5
minimongo@1.4.4
mobile-experience@1.0.5
mobile-status-bar@1.0.14
modern-browsers@0.1.2
modules@0.12.2
modules-runtime@0.10.0
momentjs:moment@2.11.1
mongo@1.5.0
mongo-dev-server@1.1.0
mongo-id@1.0.7
npm-bcrypt@0.9.3
npm-mongo@3.0.11
observe-sequence@1.0.16
ordered-dict@1.1.0
perak:mqtt-collection@1.0.4
promise@0.11.1
raix:eventddp@0.0.2
raix:eventemitter@0.1.3
random@1.1.0
rate-limit@1.0.9
reactive-dict@1.2.0
reactive-var@1.0.11
reload@1.2.0
retry@1.1.0
routepolicy@1.0.13
service-configuration@1.0.11
session@1.1.7
sha@1.0.9
socket-stream-client@0.2.1
spacebars@1.0.15
spacebars-compiler@1.1.2
srp@1.0.10
standard-minifier-css@1.4.1
standard-minifier-js@2.3.4
standard-minifiers@1.1.0
templating@1.2.14
templating-tools@1.1.1
tracker@1.2.0
underscore@1.0.10
urigo:cancel-fastclick@0.0.2
url@1.2.0
webapp@1.6.0
webapp-hashing@1.0.9

Here is my npm package info:

"version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "meteor run",
    "debug": "meteor run --inspect-brk=9229"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "eslint": "^3.19.0",
    "eslint-plugin-meteor": "^4.0.1"
  },
  "dependencies": {
    "@babel/runtime": "7.0.0-beta.55",
    "angular": "^1.7.8",
    "angular-meteor": "^1.3.12",
    "meteor-node-stubs": "^0.4.1"
  },
  "directories": {
    "lib": "lib"
  },
  "description": ""

Here is a snippet of the routing component:

angular
    .module('myModule')
    .config(config);

function config($stateProvider, $urlRouterProvider, $locationProvider) {
    // $locationProvider.html5Mode(true); // requires <base> tag!
    $urlRouterProvider.otherwise(function ($injector) {
        var $state = $injector.get('$state');

        if (Meteor.userId() == null) {
            $state.go('app.home');
        }
        else {
            var $ionicHistory = $injector.get('$ionicHistory');
            $ionicHistory.nextViewOptions({
                disableBack: true
            });
            $state.go('app.pageMain');
        }
    });

    $stateProvider
        .state('app', {
            url: '/app',
            abstract: true,
            templateUrl: 'client/sideMenu/sideMenu.html',
            controller: 'SideMenuCtrl',
            controllerAs: 'SideMenuCtrl'
        })
        .state('app.home', {
            url: '/home',
            views: {
                'menuContent': {
                    templateUrl: 'client/main/pageHome.html',
                    controller: 'pageHomeCtrl'
                }
            }
        })

        .state('app.pageMain', {
            cache: false,
            url: '/pageMain',
            views: {
                'menuContent': {
                    templateUrl: 'client/main/pageMain.html',
                    controller: 'pageMainCtrl',
                    controllerAs: 'pageMainCtrl'
                }
            }
        })
        .state('app.deviceStatus', {
            url: '/deviceStatus',
            views: {
                'menuContent': {
                    templateUrl: 'client/devices/deviceStatus.html',
                    controller: 'DeviceStatusCtrl',
                    resolve: {
                        currentUser: ($q) => {
                            if (Meteor.userId() == null) {
                                return $q.reject('AUTH_REQUIRED');
                            }
                            else {
                                return $q.resolve();
                            }
                        }
                    }
                }
            }
        })

When I inspected Meteor.userId(), it does have the correct value after logging in. This seems to be a dependency injection issue. However, I don’t know why this is related to Meteor.

Other things that I think are worthy mentioning is that I haven’t got time to strictly follow import rules to import Meteor packages as recommended in the Migrating to Meteor 1.3 documentation and my application does not strictly follow the current recommended application structure and directory layout. I’m uncertain if these two factors may cause such issue. Please give me some advice on this issue and tell me if you need more information. Thanks in advance!