angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

Angular v6 build with AOT and buildOptimizer failed at runtime #3689

Closed boltzj closed 6 years ago

boltzj commented 6 years ago

After upgrading to angular v6

Fails at runtime :

transitionService.js:180 Uncaught TypeError: Cannot read property 'STATE' of undefined
    at e._defineCorePaths (transitionService.js:180)
    at new e (transitionService.js:73)
    at new e (router.js:62)
    at y (providers.js:113)
    at core.js:9214
    at xi (core.js:9168)
    at core.js:9099
    at new e (core.js:9817)
    at Object.Ji [as createNgModuleRef] (core.js:9806)
    at t.create (core.js:12337)

Callstack:

    // ----------------- Create router -----------------
    // Create a new ng2 UIRouter and configure it for ng2
>>    var router = new UIRouter();
    function UIRouter(locationService, locationConfig) {
        if (locationService === void 0) {
            locationService = urlService_1.UrlService.locationServiceStub;
        }
        if (locationConfig === void 0) {
            locationConfig = urlService_1.UrlService.locationConfigStub;
        }
        this.locationService = locationService;
        this.locationConfig = locationConfig;
        /** @hidden */ this.$id = _routerInstance++;
        /** @hidden */ this._disposed = false;
        /** @hidden */ this._disposables = [];
        /** Provides trace information to the console */
        this.trace = trace_1.trace;
        /** Provides services related to ui-view synchronization */
        this.viewService = new view_1.ViewService();
        /** Global router state */
        this.globals = new globals_1.UIRouterGlobals();
        /** Provides services related to Transitions */
>>        this.transitionService = new transitionService_1.TransitionService(this);
var TransitionService = /*@__PURE__*/ (function () {
    /** @hidden */
    function TransitionService(_router) {
        /** @hidden */
        this._transitionCount = 0;
        /** @hidden The transition hook types, such as `onEnter`, `onStart`, etc */
        this._eventTypes = [];
        /** @hidden The registered transition hooks */
        this._registeredHooks = {};
        /** @hidden The  paths on a criteria object */
        this._criteriaPaths = {};
        this._router = _router;
        this.$view = _router.viewService;
        this._deregisterHookFns = {};
        this._pluginapi = common_1.createProxyFunctions(hof_1.val(this), {}, hof_1.val(this), [
            '_definePathType',
            '_defineEvent',
            '_getPathTypes',
            '_getEvents',
            'getHooks',
        ]);
>>        this._defineCorePaths();
    TransitionService.prototype._defineCorePaths = function () {
>>        var STATE = interface_1.TransitionHookScope.STATE, TRANSITION = interface_1.TransitionHookScope.TRANSITION;

From the debugger : interface_1 is defined in the Closure (OEBj) :

interface_1 : {
  __esModule : true
  __proto__ : { ... }

This is a :

My version of UI-Router is: 1.0.1 & 1.1.0

Bug Report

Current Behavior:

Works with build without buildOptimizer:

      "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            ...
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "aot": true,
              "buildOptimizer": false,
              "outputHashing": "all",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "serviceWorker": true
            }
          }
        },

Fail at runtime with "buildOptimizer": true:

      "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            ...
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "aot": true,
              "buildOptimizer": true,
              "outputHashing": "all",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "serviceWorker": true
            }
          }
        },

Expected Behavior:

ui-router works with build option: buildOptimizer: true

Link to Plunker or stackblitz that reproduces the issue:

Repo coming soon

Feature Request

Use UI Router with latest angular version

boltzj commented 6 years ago

Bad repo