question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tutorial] Cannot read property 'initialize' of undefined

See original GitHub issue

I followed the instructions for creating the db tutorial. I got the following error Unhandled JS Exception: TypeError: Cannot read property 'initialize' of undefined. Thinking I did something wrong, I recreated it. Same error. I’ve scoured the internet for a solution without success.

My environment package.json

{
  "name": "movie_directory",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@nozbe/watermelondb": "^0.16.1",
    "@nozbe/with-observables": "^1.0.5",
    "native-base": "^2.13.12",
    "rambdax": "^3.7.0",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-fullwidth-image": "^0.1.3",
    "react-native-gesture-handler": "^1.6.1",
    "react-navigation": "^4.3.9"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/plugin-proposal-decorators": "^7.8.3",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "react-test-renderer": "16.11.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

The error occurs in the index.js file when it can’t initialize the SQLiteAdapter. Is there any known issues with using Watermelon with the latest react-native version? This is a blocker because the app does not compile.

Here is the index.js file // index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import {Database} from '@nozbe/watermelondb';
import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite';
import {mySchema} from './src/models/schema';
import {dbModels} from './src/models/index.js';

// First, create the adapter to the underlying database:
const adapter = new SQLiteAdapter({
  dbName: 'WatermelonDemo',
  schema: mySchema,
});

// Then, make a Watermelon database from it!
const database = new Database({
  adapter,
  modelClasses: dbModels,
});

AppRegistry.registerComponent(appName, () => App);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
mjstellycommented, Jun 3, 2020

I’m reopening because the issue still exists when working from a fresh install. Thanks, @jdnichollsc for assistance. But your app is written in Typescript which I don’t use. I followed the tutorial verbatim except for passing the database object to the navigation handler. I don’t need it for this PoC. Also, I factored db ops into it’s own component.

Database.js

import {Database} from '@nozbe/watermelondb';
import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite';

import {mySchema} from '../models/schema';
import {Post, Comment} from '../models/Post';

// First, create the adapter to the underlying database:
const adapter = new SQLiteAdapter({
  mySchema,
});

// Then, make a Watermelon database from it!
const HomeeDb = new Database({
  adapter,
  modelClasses: [Post, Comment],
  actionsEnabled: true,
});

export default HomeeDb;

I import this into App.js with import {HomeeDb} from './services/Database'; Then call it with const db = HomeeDb();. The app crashes when trying to initialize the adapter. I tried to step through it but it’s crashing in the node module.

1reaction
mjstellycommented, May 31, 2020

Thanks, @jdnichollsc, your demo may come in handy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'initialize' of ...
Currently I am working on an Upgradation project; I am facing the Below Exception when I instantiate the Custom Router Class from the...
Read more >
Uncaught TypeError: Cannot read property ... - SAP Community
Hi, I have developed UI5 application and deployed into ABAP server. When I try to run on ABAP server from Eclipse it is...
Read more >
Cannot read properties of undefined' - JavaScript Debugging
JavaScript Tutorial. How To Fix 'Uncaught TypeError: Cannot read properties of undefined ' - JavaScript Debugging. 26K views 6 months ago.
Read more >
ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE ! ... Your browser can't play this video. ... Solved: ERROR TypeError: Cannot read property title of undefined....
Read more >
Uncaught TypeError : Cannot read properties of undefined
As we are discussing the Error Uncaught TypeError: Cannot read property of undefined, let's understand the JavaScript built-in error first, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found