Cardshifter / HTML-Client

HTML/CSS/JS-based client for Cardshifter
http://cardshifter.zomis.net
Apache License 2.0
13 stars 5 forks source link

AngularJS problem #139

Closed Zomis closed 6 years ago

Zomis commented 6 years ago
vendor.js:7 Error: [$injector:unpr] Unknown provider: eProvider <- e <- CardshifterServerAPI
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=eProvider%20%3C-%20e%20%3C-%20CardshifterServerAPI
    at http://gbg.zomis.net:22739/assets/vendor.js:6:381
    at http://gbg.zomis.net:22739/assets/vendor.js:6:19718
    at Object.r [as get] (http://gbg.zomis.net:22739/assets/vendor.js:6:18888)
    at http://gbg.zomis.net:22739/assets/vendor.js:6:19815
    at r (http://gbg.zomis.net:22739/assets/vendor.js:6:18888)
    at Object.i [as invoke] (http://gbg.zomis.net:22739/assets/vendor.js:6:19225)
    at Object.$get (http://gbg.zomis.net:22739/assets/vendor.js:6:17695)
    at Object.i [as invoke] (http://gbg.zomis.net:22739/assets/vendor.js:6:19258)
    at http://gbg.zomis.net:22739/assets/vendor.js:6:19835
    at r (http://gbg.zomis.net:22739/assets/vendor.js:6:18888) <div data-ng-view="" class="ng-scope">

Perhaps this question on Stack Overflow can help? https://stackoverflow.com/q/12339272/1310566

punmechanic commented 6 years ago

If I had to guess, this is because CardshifterServerAPI has no $inject property but expects one argument, debug:

https://github.com/Cardshifter/HTML-Client/blob/772eb289d65be8f51440245aa9beb1d099e4ad92/src/server_interface/server_interface.js#L60

When the code is uglified, debug is changed to e and Angular attempts to resolve a dependency with the name e. It doesn't find that, so it looks for eProvider, which doesn't exist, so Angular throws a runtime error.

debug shouldn't be a dependency here anyway - debug is a library in package.json and is never registered with Angular.

punmechanic commented 6 years ago

The PR I've created imports the debug library and consumes it directly, but if you'd prefer you could always register debug with the Angular dependency injector:

var debug = require('debug')
angular.module('....')
  // using a constant because service will result in angular trying to `new debug`.
  .constant('debug', debug)

function CardshifterServerAPI(debug) {
   ..
}
// prevents minification breaking things
CardshifterServerAPI.$inject = ['debug'];

Alternatively, one could use $log which is the included dependency for this.

function CardshifterServerAPI($log) {
   $log.debug('hello, world')
}
CardshifterServerAPI.$inject = ['$log'];

debug is mostly used by Node CLIs applications, I'm not sure it makes sense in an Angular one

punmechanic commented 6 years ago

Woops, my bad, debug is already registered in the injector, so all that's required is an $inject property

Phrancis commented 6 years ago

Closing as no longer needed #144