javascript - 迁移到 Meteor 1.7 会导致 Unknown provider: Meteor.userId( Exception
问题描述
我目前正在开发一个使用 AngularJS 和 ionic 作为前端组件的 Meteor 应用程序。我的目标是将它从 Meteor 1.2 迁移到 1.8。现在,我正处于将我的应用程序从 1.6.1.4 迁移到 1.7.0.5 的阶段。它在 Meteor 1.6.1.4 中运行良好,但是当我将 Meteor 更新到 1.7 时路由停止工作。编译时和运行时都没有错误。但是,如果我调试我的应用程序(在 chrome 或 vscode 中)并允许捕获所有异常,则每当我尝试导航到其他路由时,都会发生异常,如下所示:
发生异常:错误
错误:[$injector:unpr] 未知提供者: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)
这是我的 Meteor 包信息:
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
这是我的 npm 包信息:
"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": ""
这是路由组件的片段:
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();
}
}
}
}
}
})
当我检查 Meteor.userId() 时,它在登录后确实具有正确的值。这似乎是一个依赖注入问题。但是,我不知道为什么这与 Meteor 有关。
我认为值得一提的其他事情是,我没有时间按照Migrating to Meteor 1.3 文档中的建议严格遵循导入规则来导入 Meteor 包,并且我的应用程序没有严格遵循当前推荐的应用程序结构和目录布局。我不确定这两个因素是否会导致这样的问题。请就这个问题给我一些建议,如果您需要更多信息,请告诉我。提前致谢!
解决方案
推荐阅读
- java - 如何在 url 中查找子路径
- php - 如果满足单个条件,php将数组元素移到第一个
- python - 如果在 Windows 7 上同时运行,两个 python 应用程序会在一段时间后崩溃
- firebase - 创建 24 小时后删除 Firestore 文档
- c++ - 像 c# 中的 ConcurrentBag 一样,cpp(MFC) 中有哪些可用的选项?
- php - 如何对这个动态创建的表中的每一列求和,如 excel
- jenkins - Github jenkins webhook 集成失败
- ruby - Clojure 相当于 ruby 的#methods 方法?
- reactjs - React TypeScript:将 base64 字符串保存到 useState
- c# - 将 JSON 反序列化为 C# 对象