Realm-js: ReferenceError: createSession is not defined

Created on 22 Jul 2020  路  10Comments  路  Source: realm/realm-js

Goals

Work with Debugger on React native 0.63

Expected Results

Application could be launch and start.

Actual Results

ReferenceError: createSession is not defined
Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

Steps to Reproduce

1 - Follow the tutorial here : https://docs.mongodb.com/realm/tutorial/react-native/
2 - Start the app and active Debug function

Version of Realm and Tooling

  • Realm JS SDK Version: 10.0.0-beta.9
  • Node or React Native: React Native 0.63
  • Client OS & Version: iOS 13
  • Which debugger for React Native: React Native Debugger 0.11.3
O-Community

Most helpful comment

Actually, I have the same problem with Android.

When launching the debug mode, the createSession error appears in chrome

With the following error in node console

info Launching Dev Tools...
Error: Unable to resolve module `./debugger-ui/ui.7beef9ab.css` from ``:

None of these files exist:
  * debugger-ui\ui.7beef9ab.css(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
  * debugger-ui\ui.7beef9ab.css\index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
    at C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\lib\transformHelpers.js:267:42
    at Server.<anonymous> (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:841:41)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:99:24)
    at _next (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:119:9)
[Thu Jul 23 2020 10:54:29.571]  BUNDLE  ./index.js


None of these files exist:
  * debugger-ui\debuggerWorker.cff11639(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
  * debugger-ui\debuggerWorker.cff11639\index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
    at C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\lib\transformHelpers.js:267:42
    at C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:1096:37
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:99:24)
    at _next (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:119:9)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Error: Unable to resolve module `./debugger-ui/debuggerWorker.cff11639` from ``:

This error seems to occur after the installation of realm

Version of Realm and Tooling

"react-native": "0.63.1",
"realm": "v10.0.0-beta.7",

All 10 comments

Actually, I have the same problem with Android.

When launching the debug mode, the createSession error appears in chrome

With the following error in node console

info Launching Dev Tools...
Error: Unable to resolve module `./debugger-ui/ui.7beef9ab.css` from ``:

None of these files exist:
  * debugger-ui\ui.7beef9ab.css(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
  * debugger-ui\ui.7beef9ab.css\index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
    at C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\lib\transformHelpers.js:267:42
    at Server.<anonymous> (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:841:41)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:99:24)
    at _next (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:119:9)
[Thu Jul 23 2020 10:54:29.571]  BUNDLE  ./index.js


None of these files exist:
  * debugger-ui\debuggerWorker.cff11639(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
  * debugger-ui\debuggerWorker.cff11639\index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
    at C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\lib\transformHelpers.js:267:42
    at C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:1096:37
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:99:24)
    at _next (C:\Users\Lucas_pc\Documents\ElectroPerrinApp\node_modules\metro\src\Server.js:119:9)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Error: Unable to resolve module `./debugger-ui/debuggerWorker.cff11639` from ``:

This error seems to occur after the installation of realm

Version of Realm and Tooling

"react-native": "0.63.1",
"realm": "v10.0.0-beta.7",

@xlucxs this warning not related for reference error. You can check this out: https://stackoverflow.com/questions/59658998/expo-unable-to-resolve-module-debugger/60755519

@wgarrido this error (reference error), its not your error. You check your starting js server command line. this is the error that your concern

I also have the same problem, this problem only appear when I import Realm from "realm";

Unfortunately Expo doesn't really support Realm: https://forums.expo.io/t/is-realm-support-for-expo-coming/31

what is the status of this issue?

Debugger in vscode also reporting this

Require cycle: node_modules/realm/lib/browser/util.js -> node_modules/realm/lib/browser/rpc.js -> node_modules/realm/lib/browser/util.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
YellowBox.js:71
ReferenceError: createSession is not defined
ExceptionsManager.js:44
Running "SHARK" with {"rootTag":11}
infoLog.js:16
Invariant Violation: "SHARK" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.

I found a way to solve this:
there are several files you need to modify, the base path is

<your_project>/node_modules/realm/

in lib/browser/index.js
add this import
import {createSession} from './session';
around line 213, change the block inside try into this

let refreshAccessTokenCallback = staticUserMethods && staticUserMethods._refreshAccessToken ? staticUserMethods._refreshAccessToken.bind(User) : () => {};
// The session ID refers to the Realm constructor object in the RPC server.
Realm[keys.id] = createSession(refreshAccessTokenCallback, debugHosts[i] + ':' + debugPort);

create new file lib/browser/cache.js

export let propertyCache = {};

export function invalidateCache(realmId) {
    if (realmId) {
        propertyCache[realmId] = {};
    }
    else {
        propertyCache = {};
    }
}

export function getRealmCache(realmId) {
    let realmCache = propertyCache[realmId];
    if (!realmCache) {
        realmCache = propertyCache[realmId] = {};
    }
    return realmCache;
}

in lib/browser/util.js

add this import

import {invalidateCache, getRealmCache} from './cache'

then remove declaration of variable propertyCache function invalidateCache and getRealmCache around line 62

in lib/browser/rpc.js
add this import

import {invalidateCache} from './cache'

At line 64, change

util.invalidateCache(realm[keys.realm]);

into

invalidateCache(realm[keys.realm]);

And finally in lib/browser/session.js
around line 56, wrap the line with if

if (info && info.data && info.data.user) {
        sessionProxy[keys.id] = info.id;
        sessionProxy[keys.type] = objectTypes.SESSION;
        sessionProxy.user = deserialize(realmId, info.data.user);
        sessionProxy.config = deserialize(realmId, info.data.config)
    }

Also the debugger may also require your PC and Phone to be connected in same WIFI

With the investigation by @deckyfx I reopen the issue. It is clearly an oversight on our side, and we will provide a fix.

In short,
I put some safety check against null or undefined variable so it does not raise errors when executed
Also should separate cache function and import only the necessary function to avoid cyclic require that I believe should improve performance

I still get the same error with "realm": "^10.0.0-beta.11"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bdebout picture bdebout  路  3Comments

laznrbfe picture laznrbfe  路  3Comments

timanglade picture timanglade  路  3Comments

fever324 picture fever324  路  4Comments

emrehayirci picture emrehayirci  路  3Comments