“Unknown provider: aProvider <- a” How do I find the original provider?

后端 未结 9 677
自闭症患者
自闭症患者 2020-12-07 08:46

When I\'m loading the minified (through UglifyJS) version of my AngularJS application, I get the following error in the console:

Unknown provider: aProvider          


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 09:34

    in order to know what the original variable name was you can change how uglify mangles the variables:

    ../node_modules/grunt-contrib-uglify/node_modulesuglify-js/lib/scope.js

    SymbolDef.prototype = {
      unmangleable: [...],
      mangle: function(options) {
        [...]
        this.mangled_name = s.next_mangled(options, this)+"_orig_"+this.orig[0].name;
        [...]
      }
    };
    

    and now the error is much more obvious

    Error: [$injector:unpr] Unknown provider: a_orig_$stateProvider
    http://errors.angularjs.org/1.3.7/$injector/unpr?p0=a_orig_%24stateProvider
    at eval (eval at  (http://example.com/:64:17), :3155:20)
    

    EDIT

    So obvious now...

    Gruntfile.js

    uglify: {
      example: {
        options: {
          beautify: true,
          mangle: true
        },
        [...]
      },
      [...]
    }
    

    ../node_modules/grunt-contrib-uglify/node_modulesuglify-js/lib/scope.js

    var numberOfVariables = 1;
    SymbolDef.prototype = {
      unmangleable: [...],
      mangle: function(options) {
        [...]
        this.mangled_name = s.next_mangled(options, this)+"_orig_"+this.orig[0].name+"_"+numberOfVariables++;
        [...]
      }
    };
    

    now each variable is mangled to a unique value that also contains the original... just open up the minified javascript and search for "a_orig_$stateProvider_91212" or whatever... you will see it in it's original context...

    couldn't be any easier...

提交回复
热议问题