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

Uncaught (in promise) TypeError: given schema is no Schema-object #77

Closed chopfitzroy closed 7 years ago

chopfitzroy commented 7 years ago

Case

Bug.

Issue

I am getting the following error when using RxDB with electron, HOWEVER this is only happen when I build the app not when I run it in dev mode.

selection_002

Info

Code

console.group('Initialize database.');
console.info('Creating user database.');
const database = await RxDB.create({
    name: 'moderator',
    adapter: 'idb'
});
console.info('Created user database.');

database.waitForLeadership().then(() => {
    console.info('leader.');
});

console.info('Creating collections.');
await Promise.all(collections.map(colData => database.collection(colData)));
console.info('Created collections.');

console.log('Start sync.');
collections.filter(col => col.sync).map(col => col.name).map(colName => database[colName].sync(url + colName + '/'));

console.groupEnd();

return database;
pubkey commented 7 years ago

How do you build the app? There is currently no build-script in the electron-example.

chopfitzroy commented 7 years ago

Hey @pubkey,

I am using electron-builder relevant package.json info below:

{
  "main": "electron/index.js",
  "scripts": {
    "app:prod": "build -wl",
  },
  "license": "MIT",
  "build": {
    "files": [
      "electron",
      "node_modules"
    ],
    "linux": {
      "target": [
        "AppImage"
      ]
    },
    "win": {
      "target": [
        "nsis"
      ]
    }
  },
  "devDependencies": {
    "electron": "^1.4.15",
    "electron-builder": "^14.1.1",
    "electron-devtools-installer": "^2.1.0",
  }
}

I am wondering if it may be something to do with webpack building the scripts but I am just using babel as per the examples so I can't see why that would effect it?

chopfitzroy commented 7 years ago

Had a quick look at the source here is what babel is rendering:

{
    name: "assignments",
    schema: {
        title: "Assignment Schema",
        description: "Describes an assignment",
        version: 0,
        type: "object",
        properties: {
            name: {
                type: "string",
                primary: !0
            },
            curriculum: {
                type: "string"
            },
            year: {
                type: "integer"
            }
        },
        required: ["curriculum", "year"]
    },
    sync: !0
}
pubkey commented 7 years ago

The schema from babel looks ok. I don't know how I should reproduce this error. Maybe you can edit our electron-example in a way to reproduce the error.

chopfitzroy commented 7 years ago

Hey @pubkey,

I had similar thoughts I will put together a minimal working example hopefully tonight and that should let me know if it is some 3rd party lib interfering or if it is actually an rxdb bug.

Will add a link to the repo once I have it up.

Cheers.

pubkey commented 7 years ago

Hi @CrashyBang Any update on this?

chopfitzroy commented 7 years ago

Hey @pubkey sorry have been slammed at work and haven't even had a chance to begin to debug this :L hope to be onto it some time this week.

Cheers.

hippycore commented 7 years ago

Same error with react-native, on release mode only

matsuo-ts commented 7 years ago

Same issue with @CrashyBang in my electron project. Writing the code with React and compile and bundle it with webpack. This issue occurs when I minify the entire code for production. No error if I bundling without minifying.

Here is the console error message.

Failed to open Database:  TypeError: given schema is no Schema-object
    at Object.$.a (RxCollection.js:609)
    at he.collection (RxDatabase.js:228)
pubkey commented 7 years ago

@matsuo-ts Can you debug into it and check what constructor.name is given here ?

pubkey commented 7 years ago

Can't reproduce atm. We need a working build on one of examples

pubkey commented 7 years ago

A workarround is to enable keep_fnames in your uglifyJS-config. Webpack-example:

new webpack.optimize.UglifyJsPlugin({
                beautify: false,
                mangle: {
                    screw_ie8: true,
                    keep_fnames: true // <-- set this to true for quickfix
                }, //prod
                compress: { //prod
                    screw_ie8: true,
                    warnings: false
                },
                comments: false //prod
            })
pubkey commented 7 years ago

This is now fixed. Thx @muneebs The changed files will be published to npm with version 4.0.0. (next week)

If you need a fixed module faster, use this commit-hash into your package.json like this:

rxdb: "git://github.com/pubkey/rxdb.git#ac079880872b8c8b90db6602c20c5c740374706f"
matsuo-ts commented 7 years ago

@pubkey Sorry for late reply and thank you for your advise.

This

A workarround is to enable keep_fnames in your uglifyJS-config. Webpack-example:

new webpack.optimize.UglifyJsPlugin({ beautify: false, mangle: { screw_ie8: true, keep_fnames: true // <-- set this to true for quickfix }, //prod compress: { //prod screw_ie8: true, warnings: false }, comments: false //prod })

works fine on version 3.0.8 but after update to 4.0.0 I encountered another error. Let me report that on the new issue.