0

我正在尝试以 AoT 方式编译我的 angular 2 项目。但是我遇到了以下问题。

这是源代码:

/// <reference path="../../typings/index.d.ts" />
import { Injectable, Inject } from '@angular/core';
import { Http } from '@angular/http';
import { AppConfig, APP_CONFIG } from '../app.config';
import 'rxjs/add/operator/toPromise';
import * as bluebird from 'bluebird';

@Injectable()
export class EventsAPIService {
    private ECI_END_POINT: string;

    constructor(private http: Http, @Inject(APP_CONFIG) config: AppConfig) {
        this.ECI_END_POINT = config.ECI_END_POINT;
    }

    getEvents() {
        console.log(typeof bluebird, bluebird);
        return new bluebird((resolve: any, reject: any) => {
            this.http.get(`${this.ECI_END_POINT}/events/all`).toPromise().then((res: any) => {
                resolve(res.json().data);
            }).catch((err: Error) => {
                console.error(err);
                reject(err);
            });
        });
    }
}

rollup.config.js

import rollup      from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs    from 'rollup-plugin-commonjs';
import uglify      from 'rollup-plugin-uglify'
//paths are relative to the execution path
export default {
  entry: 'dist/src/main.js',
  dest: 'www/scripts/main.js', // output a single application bundle
  sourceMap: true,
  sourceMapFile: 'www/scripts/app.min.js.map',
  format: 'umd',
  moduleName: 'ECIAPP',
  plugins: [
    nodeResolve({jsnext: true, main: true, module: true}),
    commonjs({
      include: ['node_modules/rxjs/**']
    }),
    // uglify()
  ]
}

我可以通过 ngc 然后 rollup 编译项目,但是,rollup 将 bluebird 模块变为 {..., default: 'actual bluebird'},因此当调用 getEvents 时,它会引发错误。

有人可以帮忙吗?

4

1 回答 1

1

tsconfig.json 中的 allowSyntheticDefaultImports: true 修复了它

于 2016-11-14T00:34:53.400 回答