0

I am trying to use Rollup to bundle and treeshake my existing project. However, I'm getting the following error.

Export 'Client' is not defined by 'C:\Users\George\Source\Repos\docs\client\service\search.service.js' Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: name (UiService)

here is my search.service.ts:

import { Injectable } from '@angular/core';
import * as elasticsearch from 'elasticsearch';
//declare var elasticsearch: any;

@Injectable()
export class SearchService {
    private Client: elasticsearch.Client;
    constructor() {
        var connectionString = 'https://paas:2664f39b6a927d0873b43fab6893ace6@bifur-eu-west-1.searchly.com';
        this.Client = new elasticsearch.Client({
            host: connectionString,
            log: 'trace'
        });
    }

    search(term: string): any {
        return this.Client.search({
            index: 'plugins',
            type: 'ds044699_mlab_com_cdc1',
            body: {
                query: {
                    multi_match: {
                        query: term,
                        fields: ['name', 'description']
                    }
                }
            }
        });
    }
}

and here is my ui.service.ts:

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';

@Injectable()
export class UiService {
    chapters: string;
    // Observable boolean streams
    navState$ = this.navStateSource.asObservable();
    chapter = this._chapter.asObservable();

    // Observable boolean sources
    private navStateSource = new Subject<boolean>();
    private _chapter: Subject<number> = new Subject<number>();

    // Service message commands
    changeNavState(showNav: boolean) {
        this.navStateSource.next(showNav);
    }

    changeChapter(chapter: number) {
        this._chapter.next(chapter);
    }
}

I can't see what is wrong with either of these files? - Where should I be looking?

George Edwards
  • 8,979
  • 20
  • 78
  • 161

1 Answers1

3

For the first error (Export 'Client' is not defined by...), you probably need to use the namedExports option with rollup-plugin-commonjs. We've just released a new version of Rollup that makes this message a bit more self-explanatory and links to the Troubleshooting page.

The second message looks like it's probably related to UglifyJS not minifying ES6 code. You might need to target ES5 in your TypeScript configuration (I think – I don't do TypeScript) or add a transform like rollup-plugin-buble or rollup-plugin-babel to convert it to ES5 before minification.

Rich Harris
  • 28,091
  • 3
  • 84
  • 99
  • Thanks so much for the answer. I am compiling this into an es2015 style module with TypeScript, you can see the compiler options [here](https://github.com/georgeedwards/docs/blob/performance/client/tsconfig-aot.json) - so it shouldn't be a commonJS module? – George Edwards Oct 12 '16 at 20:15