realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.76k stars 572 forks source link

Cannot read property 'indexOf' of undefined #5027

Open ahmedmukhtar1133 opened 1 year ago

ahmedmukhtar1133 commented 1 year ago

How frequently does the bug occur?

All the time

Description

We were using realm-websdk in our electron app but that was producing some issue in production mode (crashing app due to native issue). So we are trying to replace web-sdk with NodeJS-SDK and it's giving error after installation.

As we are installing package in existing app so we cannot change electron and nodejs version yet. So we are using fixed versions for electron and node for now.

Stacktrace & log output

uncaught TypeError: Cannot read property 'indexOf' of undefined
    at Function.getFileName (webpack-internal:///…ngs/bindings.js:178)
    at bindings (webpack-internal:///…ings/bindings.js:82)
    at eval (webpack-internal:///…alm/lib/index.js:26)
    at Object../node_modules/realm/lib/index.js (main-bundle.js:90022)
    at __webpack_require__ (main-bundle.js:790)
    at fn (main-bundle.js:101)
    at Module.eval (webpack-internal:///…p/database/db.js:36)
    at eval (webpack-internal:///…/database/db.js:819)
    at Module../app/database/db.js (main-bundle.js:1913)
    at __webpack_require__ (main-bundle.js:790)
    at fn (main-bundle.js:101)
    at Module.eval (webpack-internal:///…b/LicenseUtils.js:5)
    at eval (webpack-internal:///…LicenseUtils.js:124)
    at Module../app/lib/LicenseUtils.js (main-bundle.js:2272)
    at __webpack_require__ (main-bundle.js:790)
    at fn (main-bundle.js:101)

Can you reproduce the bug?

Yes, always

Reproduction Steps

Version

v11.0.0

What SDK flavour are you using?

Atlas App Services (auth, functions, etc.)

Are you using encryption?

No, not using encryption

Platform OS and version(s)

MacOs M1 Chip

Build environment

ELECTRON: 12.3 REACTJS: 17.0.2 NodeJS: 14.17.0

Cocoapods version

1.11.2

kneth commented 1 year ago

Switching from Realm Web to Realm JavaScript is not trivial. The two SDKs have the same API but they have two very different implementations.

ahmedmukhtar1133 commented 1 year ago

@kneth

stoefln commented 1 year ago

Here someone claims that realm-js needs to be externalized from webpack: https://github.com/realm/realm-js/issues/4157 we didn't do that. Could this be the reason? I just tried to add realm to externals like this, but didn't change anything. Same error.

  externals: {
    'realm': 'realm'
  },
kneth commented 1 year ago

@stoefln

https://github.com/realm/realm-js/issues/4157 is an issue created by us to track the fix of it. Yes, it is likely you have found the solution.

stoefln commented 1 year ago

@kneth sorry, like I wrote it doesn't help us to add the module to externals. So what do you mean by "It's likely you have found the solution"?

kneth commented 1 year ago

@stoefln Sorry for the late reply. Honestly I can't remember what I meant. Please take a look at Realm Studio's webpack configuration to see how our Electron is set up.

Giayychan commented 1 year ago

I found the problem came from not having realm in the /release/app/package.json as a dependency, so I just add it there and also add "@types/realm": "^1.13.0" in ./package.json in root folder to shut typescript up.

https://electron-react-boilerplate.js.org/docs/adding-dependencies https://github.com/amilajack/erb-sqlite-example - can look into this example since realm is similar to sqlite