typeorm / ionic-example

Example project to demonstrate TypeORM in an Ionic app
67 stars 56 forks source link

Test with ionic serve #6

Closed AndresKrapf closed 6 years ago

AndresKrapf commented 6 years ago

I could run the sample both on emulator and device, but I cannot do it on browser. I get a runtime error:

Error: Uncaught (in promise): TypeError: Cannot read property 'openDatabase' of undefined TypeError: Cannot read property 'openDatabase' of undefined at http://localhost:8100/build/vendor.js:143551:26 at new t (http://localhost:8100/build/polyfills.js:3:20014) at CordovaDriver.createDatabaseConnection (http://localhost:8100/build/vendor.js:143550:16) at CordovaDriver. (http://localhost:8100/build/vendor.js:40604:51)...

Screenshot: typeormerror

daniel-lang commented 6 years ago

The cordova plugin that this example needs to run (cordova-sqlite-storage) doesn't work in the browser. You will have to use another driver (websql or sql.js) when you want to run your app in the browser.

AndresKrapf commented 6 years ago

Ok. I have changed the connection options in order to use websql driver (type = "websql") but it seems to ignore it, since the same error as before appears.

daniel-lang commented 6 years ago

You have to adapt more of your connection options to use websql (size, description and version are needed), otherwise it won't compile. If you still get same error: Could you take a look at the line in vendor.js in which it tries to call openDatabase(). Because the object that openDatabase() gets called on when using websql is window that shouldn't be undefined.

AndresKrapf commented 6 years ago

Actually I am setting those options, as: type: "websql", database: "testdb.db", version: "1.0", description: "test in browser", size: 2 1024 1024, entities: [ Author, Category, Post ]

I get the same error: "Cannot read property 'openDatabase' of undefined at http://localhost:8100/build/vendor.js:143551:26"

The codeline 143551 is: _this.sqlite.openDatabase({ name: _this.options.database, location: _this.options.location }, function (db) {

It seems to ignore websql type option.

daniel-lang commented 6 years ago

That is strange. Can you create a repo where I can look at your code and try it out?

AndresKrapf commented 6 years ago

yes, I'll do that. I see taht ionic serve command results in server: --address 0.0.0.0 --port 8100 --livereload-port 35729 --dev-logger-port 53703 --nobrowser

I guess the option "-nobrowser" could be the problem, right? where can I change that?

AndresKrapf commented 6 years ago

Here is the repo. https://github.com/AndresKrapf/typeorm-browser-ionic-example

daniel-lang commented 6 years ago

--nobrowser tells you whether or not a browser window will be opened. There seems to a bug because that option is always listed. It should only listed when calling ionic serve --no-open as this starts the server but doesn't open a browser window.

Since you created a new repo it is very hard for me to find differences but I'm able to run this example which these options and ionic serve (typeorm@0.1.9):

 await createConnection({
   type: 'websql',
   database: 'test',
   description: 'test in browser',
   version: '1.0',
   size: 2 * 1024 * 1024,
   logging: ['error', 'query', 'schema'],
   synchronize: true,
   entities: [
      Author,
      Category,
      Post
   ]
});

image

Is there anything else that you changed?

AndresKrapf commented 6 years ago

I didn't change anything else. Anyway, I did copy/paste of the connection options as you posted and it is working fine. There was an issue with the connection options. Thanks.