2

When I require the Angular library with Browserify, I get an 'Uncaught object' error in bundle.js. It seems like Browserify has a problem with the Angular library? All other required files work with no errors. Can someone help me solve this please?

In my index.js file I do this 'require('./angular');' Which works as expected and bundles the file. Below are screenshots of the console errors.

enter image description here From Console

user2808895
  • 438
  • 1
  • 6
  • 14
  • angular is not CommonJS (or AMD for that matter). To `require` it with browserify you'd have to shim it. Personally I've found this combo to be such a PITA that I just load angular normally and use the global variable within browserify modules. – numbers1311407 Jun 26 '14 at 23:11
  • Could you try `require`ing Angular from some other file (say, `common.js`) and then requiring `common.js` in your angular module file? I'm not sure if this is the reason my app is working, but it very well could be. Here's my `common` file: https://github.com/prajwalkman/magrathea/blob/master/frontend/src/common.coffee – abject_error Jun 27 '14 at 00:05

1 Answers1

1

Browserify is not your issue in this case. There is a misconception that you cannot use libraries with Browserify without shims. Actually you can. I use both Angular, and Angular-Route fetched via Bower with Browserify just fine.

The uncaught object is an AngularJS error. More than likely due to incorrect dependancy loading. Several mentions with NgRoute on SO here, here, and here

Community
  • 1
  • 1
mikekidder
  • 888
  • 8
  • 13
  • You are right. This was really careless of me. Browserify works fine with Angular. The problem was that I had misnamed my main app controller. The message wasn't descriptive so I assumed it was a Browserify issue. – user2808895 Jul 01 '14 at 13:55
  • The generic "uncaught object" error message will hopefully be soon behind us. This is a combination of when Angular introduced ngMinErr (robust error message utility) under the hood starting in 1.2.x, and a Chrome bug that made its way into the #stable branch. A fix in recent version of Chrome Canary will show the error messages as intended. – mikekidder Jul 01 '14 at 15:49