pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

The babel-polyfill causes typescript build errors #46

Closed thani-sh closed 7 years ago

thani-sh commented 7 years ago

The babel-polyfill causes build errors when used with Ionic2.

Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.
    Most likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.) in /path/to/my/project/node_modules/zone.js/dist/zone.js (line 42)
thani-sh commented 7 years ago

As a temporary fix, restore the Promise replaced by babel-polyfill.

const _Promise = Promise;
const RxDB = require('rxdb');
Promise = _Promise;
pubkey commented 7 years ago

You are right. Including the polyfill for everyone is not the final solution. I will figure out a better solution. Maybe someone has a hint on how other npm-libs handle the problem of including polyfills.

Lyoko-Jeremie commented 7 years ago

i have the same problem in angular2 with angular-cli

i add those code in polyfill.ts to make es6-promise polyfilled before zone.js init.

import 'core-js/es6/promise';

then, i can use es6 import style like that:

import * as RxDB from "rxdb";
import {RxDatabase, create as createRxDB, RxSchema, RxCollection} from 'rxdb';
import * as pouchDBAdapterIdb from 'pouchdb-adapter-idb';
import * as pouchDBAdapterWebsql from "pouchdb-adapter-websql";

RxDB.plugin(pouchDBAdapterIdb);
RxDB.plugin(pouchDBAdapterWebsql);

and than, i can use follow code in typescript:

    cacheRxDatabase: RxDatabase;
    cacheRxSchema: RxSchema;
    cache: RxCollection;

and, mnmtanish's way case typescript cannot use type info, i hate that way.

then, please fix this issue,thx. @pubkey and, may be can not include pollyfill in rxdb, but include it with manual and say it in document?

pubkey commented 7 years ago

@Lyoko-Jeremie Yes I know of this problem. As mentioned here, polyfills will not be included when v3.0.0 is out.

Lyoko-Jeremie commented 7 years ago

@pubkey nnnn, how long will v3 release ?

pubkey commented 7 years ago

Check out the MILESTONE, in about 2 weeks.

pubkey commented 7 years ago

@Lyoko-Jeremie . It's released now. Can you check if the polyfill-problem is solved?

pubkey commented 7 years ago

Closing this since no response. It should work in RxDB v3 now, reopen if you think otherwise.