2017-01-03 118 views
2

我正在使用角度1.6,webpack,gulp和typescript創建初學者模板。我能夠編譯和構建我的應用程序,但應用程序不是自舉。這個問題很奇怪,因爲當我正在調試angular.module已定義,模塊可以從控制檯angular.module('testModule', [])創建,但作爲恢復調試器,我得到異常core.module.tsexport const CoreModule = angular.module('app.core', []).name;angular_1.default.module Uncaught TypeError:無法讀取未定義的屬性「模塊」

我通過禁用源代碼進一步調查了這個問題,並且發現了問題。上述代碼編譯爲exports.CoreModule = angular_1.default.module('app.core', []).name;,在angular_1上沒有名爲default的屬性。 對於代碼是指https://github.com/muditsaurabh/awesome-ng-starter

Uncaught TypeError: Cannot read property 'module' of undefined 
    at Object.<anonymous> (app.bundle.js?cd4d443…:1) 
    at e (vendor.bundle.js?cd4d443…:1) 
    at Object.<anonymous> (app.bundle.js?cd4d443…:1) 
    at e (vendor.bundle.js?cd4d443…:1) 
    at Object.<anonymous> (app.bundle.js?cd4d443…:1) 
    at e (vendor.bundle.js?cd4d443…:1) 
    at window.webpackJsonp (vendor.bundle.js?cd4d443…:1) 
    at app.bundle.js?cd4d443…:1 
vendor.bundle.js?cd4d443…:6Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: 
Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 
http://errors.angularjs.org/1.6.1/$injector/nomod?p0=app 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:377 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:11230 
    at n (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:10668) 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:11004 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:20796 
    at r (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:809) 
    at h (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:20644) 
    at le (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:22631) 
    at a (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8560) 
    at st (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8870) 
http://errors.angularjs.org/1.6.1/$injector/modulerr?p0=app&p1=Error%3A%20%…2F%2Flocalhost%3A8000%2Fvendor.bundle.js%3Fcd4d4432605c6f5be56a%3A6%3A8870) 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:377 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:11230 
    at n (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:10668) 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:11004 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:20796 
    at r (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:809) 
    at h (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:20644) 
    at le (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:22631) 
    at a (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8560) 
    at st (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8870) 
http://errors.angularjs.org/1.6.1/$injector/modulerr?p0=app&p1=Error%3A%20%…2F%2Flocalhost%3A8000%2Fvendor.bundle.js%3Fcd4d4432605c6f5be56a%3A6%3A8870) 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:377 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:21073 
    at r (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:809) 
    at h (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:20644) 
    at le (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:22631) 
    at a (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8560) 
    at st (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8870) 
    at at (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:8109) 
    at http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:11:13916 
    at HTMLDocument.n (http://localhost:8000/vendor.bundle.js?cd4d4432605c6f5be56a:6:17809) 
+0

我們需要更多的信息,你的webpack.config和你的入口文件是怎樣的? – Dieterg

+0

@Dieterg我已添加git repo鏈接,請克隆它以查看代碼 –

+0

@Dieterg我通過禁用源映射進一步調查了此問題,並且發現了該問題。上述代碼編譯爲exports.CoreModule = angular_1.default.module('app.core',[])。name;在angular_1上沒有名爲default的屬性 –

回答

1

你肯定AngularJS得到你的腳本之前包括在內?該錯誤意味着對象角度還沒有被Javascript看到,因此模塊不能被調用。

+0

我能夠從控制檯獲取角度對象,但是當我跨越'export const CoreModule = angular.module('app.core',[])。name;'將代碼I得到例外。我認爲這個錯誤是誤導性的。 –

4

我已將import angular from 'angular'替換爲import * as angular from 'angular',現在工作正常。

+1

但爲什麼這是必要的?我在'node_modules/angular'中看到一個index.js文件,該文件將默認導出設置爲'angular'(本v 1.6) – user2954463