OP-Engineering / op-sqlite

Fastest SQLite library for react-native by @ospfranco
MIT License
598 stars 41 forks source link

Error: Base module not found. Maybe try rebuilding the app., js engine: hermes #98

Closed cobasajaxinpho closed 6 months ago

cobasajaxinpho commented 6 months ago

Hi hello,

Currently i trying to embedded op-sqlite library into the project that i'm working on in react native, typescript using expo format. Which after npm install upon running via iOS, i got an error

ERROR Error: Base module not found. Maybe try rebuilding the app., js engine: hermes ERROR Invariant Violation: "main" has not been registered. This can happen if:

React version: 18.2.0 Expo: 50.0.15 Screenshot 2024-05-16 at 5 25 24 PM

ospfranco commented 6 months ago

Did you do a pod install?

cobasajaxinpho commented 6 months ago

Hi @ospfranco , currently i'm using nx, which it resolve after i copy inside the dependency inside /apps folder

ospfranco commented 6 months ago

I don't know what NX is. It's better you ask on stack overflow

cobasajaxinpho commented 6 months ago

I don't know what NX is. It's better you ask on stack overflow

Thank you. i manage to fix it. I'm writing some unit test pertaining to database for react native. code as follows:

import { open, OPSQLiteConnection } from '@op-engineering/op-sqlite';

jest.mock('@op-engineering/op-sqlite', () => {
  const mockedConnection: OPSQLiteConnection = {
    close: jest.fn(),
    delete: jest.fn(),
    attach: jest.fn(),
    detach: jest.fn(),
    transaction: jest.fn(),
    execute: jest.fn(),
    executeAsync: jest.fn(),
    executeBatch: jest.fn(),
    executeBatchAsync: jest.fn(),
    loadFile: jest.fn(),
    updateHook: jest.fn(),
    commitHook: jest.fn(),
    rollbackHook: jest.fn(),
    prepareStatement: jest.fn(),
    loadExtension: jest.fn(),
    executeRawAsync: jest.fn(),
    getDbPath: jest.fn(),
  };

  return {
    open: jest.fn(() => mockedConnection),
    isSQLCipher: jest.fn(),
    moveAssetsDatabase: jest.fn(),
  };
});

describe('Test Service', () => {
  describe('DatabaseAction', () => {
    it('should handle the database function correctly', async () => {
      const db = open({
        name: 'test',
      });
      const result= db.execute('select sqlite_version();');
      expect(result).toBeDefined();
    });
  });
});

it keep give me result undefined. any idea, what's wrong with that? i try setting up location ':memory:' or even put the absolute path '/Users/user/database' also same result.

ospfranco commented 6 months ago

No idea, any mocks should work.

cobasajaxinpho commented 6 months ago

No idea, any mocks should work.

Weird thing is i create a new project react-native using the same code it have the same result. >.<

ospfranco commented 6 months ago

well... your code is wrong right? you mocked execute to be a jest.fn() but you are not returning any value, so toBeDefined will fail. Anyways, there is nothing wrong with the module so going to close this ticket for good.