2014-10-19 79 views
8

我使用Browserify來包裝所有東西。我剛剛從升級到1.2.231.3.0我現在得到以下錯誤:已更新至Angular 1.3.0不再有效

Firefox的錯誤

TypeError: angular.module is not a function 

var app = angular.module('login-Controller', ['Views']); 
    ----------^ 

顯然說的角度是沒有定義。所以我outputed從角

var angular = require('angular'), 
console.info(angular); // Object {} ='s an empty object 

輸出這是否意味着角沒有與browserify不再兼容?如果是這樣,我怎麼才能使它工作?

從Chrome中詳細的錯誤

Uncaught TypeError: undefined is not a function main.js:25868 C:\var\www\stage.mayfieldafc.com\src\site\js\users\loginCntrl.js.angularmain.js:1 smain.js:1 (anonymous function)main.js:28 ./src/site/js/app.js.angularmain.js:1 smain.js:1 emain.js:1 (anonymous function) 
main.js:183 Uncaught Error: [$injector:modulerr] Failed to instantiate module mays due to: 
Error: [$injector:nomod] Module 'mays' 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.3.0/$injector/nomod?p0=mays 
    at http://localhost:3000/js/main.js:183:12 
    at http://localhost:3000/js/main.js:1900:17 
    at ensure (http://localhost:3000/js/main.js:1824:38) 
    at module (http://localhost:3000/js/main.js:1898:14) 
    at http://localhost:3000/js/main.js:4167:22 
    at forEach (http://localhost:3000/js/main.js:438:20) 
    at loadModules (http://localhost:3000/js/main.js:4151:5) 
    at createInjector (http://localhost:3000/js/main.js:4077:11) 
    at doBootstrap (http://localhost:3000/js/main.js:1587:20) 
    at bootstrap (http://localhost:3000/js/main.js:1608:12) 
http://errors.angularjs.org/1.3.0/$injector/modulerr?p0=mays&p1=Error%3A%20…at%20bootstrap%20(http%3A%2F%2Flocalhost%3A3000%2Fjs%2Fmain.js%3A1608%3A12)main.js:183 (anonymous function)main.js:4190 (anonymous function)main.js:438 forEachmain.js:4151 loadModulesmain.js:4077 createInjectormain.js:1587 doBootstrapmain.js:1608 bootstrapmain.js:1502 angularInitmain.js:25682 (anonymous function)main.js:2845 triggermain.js:3116 eventHandler 

標記

html(ng-app='mays) 
+1

我與Angular 1.3和Browserify有完全相同的問題。 Angular對象是空的,所以對'angular.module'的調用是不確定的。看起來像npm下載的Angular版本不會導出任何內容。任何決議呢? – Jakemmarsh 2014-10-20 16:47:26

+0

你說的是確切的問題。我會添加答案,我如何修復它。它是一個血腥的可怕的可怕...可怕的哈克KD: – 2014-10-20 16:52:23

回答

12

正如@JeffB所述,您可以使用browserify-shim(希望暫時)來解決此問題。

首先,npm install --save-dev browserify-shim。然後,添加以下到您package.json

"browserify": { 
    "transform": [ 
     "browserify-shim" 
    ] 
    }, 
    "browser": { 
    "angular": "./node_modules/angular/angular.js" 
    }, 
    "browserify-shim": { 
    "angular": "angular" 
    } 

這應該然後讓你require和訪問角預期。

+0

這意味着你必須從包中刪除它,否則你會得到名稱衝突..:/ – 2014-10-21 09:36:52

+0

@JamieHutber我不確定你的意思?我現在在一個項目中工作,沒有更多的變化 – Jakemmarsh 2014-10-21 13:55:19

+1

這給我工作給了同樣的錯誤。非常感謝! – isTravis 2014-10-28 19:13:20

0

它看起來像你定義模塊名稱是 '登陸 - 控制器' 在你的腳本,但調用它'mays'在您的標記。我期望看到類似這樣的東西:

//declare app in main.js 
angular.module('name-of-app', [<modules>]) 

<!-- call your app in markup --> 
<html ng-app="name-of-app"></html> 

//jade 
html(ng-app='name-of-app') 
+0

它爲什麼在角1.2.23工作? – 2014-10-19 21:32:38

+1

我不認爲這是問題。這當然是* A *問題,但我認爲這與Browserify要求的Angular對象爲空無關。 – Jakemmarsh 2014-10-20 16:46:31

1

問題是角沒有更新他們的npm包以與browserify兼容。

我的修復令人厭惡,但它的工作。我只是下載v1.3.0並粘貼成:

node_modules\angular\lib\angular.min.js 

現在browserify將編譯並使用最新版本。我希望這是一個臨時修復,直到他們更新軟件包。

+0

你不能使用browserify-shim而不是這樣做嗎?這就是我在1.3中所做的。 – JeffB 2014-10-20 17:08:07

+0

我在填補名字時遇到名稱衝突。 – 2014-10-21 09:37:34