Search code examples
angularecmascript-6babeljsrolluprollupjs

Why does ngc + Rollup bundled Angular 2 RC.6 routing fail?


I'm trying to take advantage of the new AOT Compiling available in RC.6 but have run into a blocker. I can successfully create a bundle with ngc => Rollup => Babel, however every time I run Rollup I get multiple warnings:

The 'this' keyword is equivalent toundefinedat the top level of an ES module, and has been rewritten

The bundle completes successfully. The same codebase works fine with JIT compiling. The Angular 2 app bootstraps and fast, but every time I try to navigate to another route other than root I get this Error:

```

bundle.js:2781 EXCEPTION: Uncaught (in promise): EmptyError: no elements in    sequenceErrorHandler.handleError @ bundle.js:2781
bundle.js:2781 ORIGINAL STACKTRACE:ErrorHandler.handleError @ bundle.js:2781
bundle.js:2781 Error: Uncaught (in promise): EmptyError: no elements in sequence
    at resolvePromise (zone.js:558)
    at zone.js:535
    at ZoneDelegate.invoke (zone.js:332)
    at Object.onInvoke (bundle.js:3549)
    at ZoneDelegate.invoke (zone.js:331)
    at Zone.run (zone.js:225)
    at zone.js:591
    at ZoneDelegate.invokeTask (zone.js:365)
    at Object.onInvokeTask (bundle.js:3549)
    at ZoneDelegate.invokeTask (zone.js:364)ErrorHandler.handleError @ bundle.js:2781
zone.js:484 Unhandled Promise rejection: no elements in sequence ; Zone: angular ; Task: Promise.then ; Value: Error: no elements in sequence
    at new EmptyError (bundle.js:7019)
    at FirstSubscriber._complete (bundle.js:7071)
    at FirstSubscriber.complete (bundle.js:3410)
    at MergeAllSubscriber._complete (bundle.js:6854)
    at MergeAllSubscriber.complete (bundle.js:3410)
    at MapSubscriber._complete (bundle.js:3410)
    at MapSubscriber.complete (bundle.js:3410)
    at EmptyObservable._subscribe (bundle.js:6598)
    at EmptyObservable.subscribe (bundle.js:3441)
    at Observable.subscribe (bundle.js:3441) EmptyError: no elements in sequence
    at new EmptyError (http://localhost:4200/bundle.js:7019:243)
    at FirstSubscriber._complete (http://localhost:4200/bundle.js:7071:1680)
    at FirstSubscriber.complete (http://localhost:4200/bundle.js:3410:99)
    at MergeAllSubscriber._complete (http://localhost:4200/bundle.js:6854:783)
    at MergeAllSubscriber.complete (http://localhost:4200/bundle.js:3410:99)
    at MapSubscriber._complete (http://localhost:4200/bundle.js:3410:547)
    at MapSubscriber.complete (http://localhost:4200/bundle.js:3410:99)
    at EmptyObservable._subscribe (http://localhost:4200/bundle.js:6598:234)
    at EmptyObservable.subscribe (http://localhost:4200/bundle.js:3441:223)
    at Observable.subscribe (http://localhost:4200/bundle.js:3441:187)consoleError @ zone.js:484
zone.js:486 Error: Uncaught (in promise): EmptyError: no elements in sequence
    at resolvePromise (zone.js:558)
    at zone.js:535
    at ZoneDelegate.invoke (zone.js:332)
    at Object.onInvoke (bundle.js:3549)
    at ZoneDelegate.invoke (zone.js:331)
    at Zone.run (zone.js:225)
    at zone.js:591
    at ZoneDelegate.invokeTask (zone.js:365)
    at Object.onInvokeTask (bundle.js:3549)
    at ZoneDelegate.invokeTask (zone.js:364)

```

ngc compiles without any warnings or errors.

My rollup.config.js is as follows:

```

// rollup.config.js
import alias from 'rollup-plugin-alias';
import resolve from 'rollup-plugin-node-resolve';


export default {
  entry: 'main.js',
  format: 'iife',
  dest: 'dist/bundle.es2015.js',
  sourceMap: false,
  plugins: [
    alias({ rxjs: __dirname + '/node_modules/rxjs-es' }),
    resolve({ module: true })
  ]
}

```

when transpiling the ES2015 bundle down to ES5 with Babel I get the following warning:

[BABEL] Note: The code generator has deoptimised the styling of "./dist/bundle.es2015.js" as it exceeds the max of "100KB".

What could possibly be the issue?

Regards, Steve


Solution

  • I couldn't get Babel 6.5.2 to correctly transpile the bundle. Upon the advice of Rob Wormald I tried to transpile the ES2015 bundle output from Rollup with Closure Compiler and it worked. Only the Java version is stable it seems but when the JS version will run smoothly I plan to integrate it with my rollup.config.js. Right now, I handle the build through a series of async callbacks in an npm script.

    https://github.com/steveblue/angular2-rollup

    https://developers.google.com/closure/compiler