我正在尝试将 angularjs(1.5.10)应用程序迁移到angular。最初,我的应用程序是使用jhipster创建的。现在我们删除了jhipster,但应用程序的结构仍然相同。
我已将所有依赖项移至package.json,并且尝试使用webpack捆绑脚本,然后在index.html页面上使用捆绑的脚本。 webpack版本为4.26.1 ,我在版本0.3.1
中使用 @ uirouter / angularjs当我运行命令运行webpack时,它成功运行并创建了捆绑文件,但是当我在浏览器中运行该应用程序时,出现以下错误:-
Uncaught Error: [$injector:modulerr] Failed to instantiate module libraryApp due to:
TypeError: Cannot read property 'navigable' of undefined
at Object.url (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2245:30)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2381:72)
at flushQueuedChildren (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2353:7)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2395:5)
at flushQueuedChildren (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2353:7)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2395:5)
at flushQueuedChildren (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2353:7)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2395:5)
at $StateProvider.state (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2877:5)
at stateConfig (webpack:///./src/main/webapp/app/app.state.ts?:16:24)
http://errors.angularjs.org/1.5.10/$injector/modulerr?p0=libraryApp&p1=TypeError%3A%20Cannot%20read%20property%20'navigable'%20of%20undefined%0A%20%20%20%20at%20Object.url%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2245%3A30)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2381%3A72)%0A%20%20%20%20at%20flushQueuedChildren%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2353%3A7)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2395%3A5)%0A%20%20%20%20at%20flushQueuedChildren%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2353%3A7)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2395%3A5)%0A%20%20%20%20at%20flushQueuedChildren%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2353%3A7)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2395%3A5)%0A%20%20%20%20at%20%24StateProvider.state%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2877%3A5)%0A%20%20%20%20at%20stateConfig%20(webpack%3A%2F%2F%2F.%2Fsrc%2Fmain%2Fwebapp%2Fapp%2Fapp.state.ts%3F%3A16%3A24)
at Object.url (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2245:30)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2381:72)
at flushQueuedChildren (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2353:7)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2395:5)
at flushQueuedChildren (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2353:7)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2395:5)
at flushQueuedChildren (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2353:7)
at registerState (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2395:5)
at $StateProvider.state (webpack:///./node_modules/@uirouter/angularjs/release/angular-ui-router.js?:2877:5)
at stateConfig (webpack:///./src/main/webapp/app/app.state.ts?:16:24)
http://errors.angularjs.org/1.5.10/$injector/modulerr?p0=libraryApp&p1=TypeError%3A%20Cannot%20read%20property%20'navigable'%20of%20undefined%0A%20%20%20%20at%20Object.url%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2245%3A30)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2381%3A72)%0A%20%20%20%20at%20flushQueuedChildren%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2353%3A7)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2395%3A5)%0A%20%20%20%20at%20flushQueuedChildren%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2353%3A7)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2395%3A5)%0A%20%20%20%20at%20flushQueuedChildren%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2353%3A7)%0A%20%20%20%20at%20registerState%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2395%3A5)%0A%20%20%20%20at%20%24StateProvider.state%20(webpack%3A%2F%2F%2F.%2Fnode_modules%2F%40uirouter%2Fangularjs%2Frelease%2Fangular-ui-router.js%3F%3A2877%3A5)%0A%20%20%20%20at%20stateConfig%20(webpack%3A%2F%2F%2F.%2Fsrc%2Fmain%2Fwebapp%2Fapp%2Fapp.state.ts%3F%3A16%3A24)
at eval (webpack:///./node_modules/angular/angular.js?:68:12)
at eval (webpack:///./node_modules/angular/angular.js?:4688:15)
at forEach (webpack:///./node_modules/angular/angular.js?:325:20)
at loadModules (webpack:///./node_modules/angular/angular.js?:4649:5)
at createInjector (webpack:///./node_modules/angular/angular.js?:4571:19)
at doBootstrap (webpack:///./node_modules/angular/angular.js?:1805:20)
at bootstrap (webpack:///./node_modules/angular/angular.js?:1826:12)
at angularInit (webpack:///./node_modules/angular/angular.js?:1711:5)
at eval (webpack:///./node_modules/angular/angular.js?:32539:5)
at HTMLDocument.trigger (webpack:///./node_modules/angular/angular.js?:3253:7)
我的app.state.js代码:-
import angular from 'angular';
(function() {
'use strict';
angular
.module('libraryApp')
.config(stateConfig);
stateConfig.$inject = ['$stateProvider'];
function stateConfig($stateProvider) {
$stateProvider.state('app', {
abstract: true,
views: {
'topbar@': {
templateUrl: 'app/layouts/topbar/topbar.html',
controller: 'TopbarController',
controllerAs: 'vm'
}
},
resolve: {
authorize: ['Auth',
function (Auth) {
return Auth.authorize();
}
]
}
});
}
})();
如果我在抽象:true 之前添加 parent:'app',控制台错误将全部消失,但 TopbarController 不会不会调用 Auth.authorize()解决方法。