Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: createSession is not defined #3085

Closed
wgarrido opened this issue Jul 22, 2020 · 10 comments
Closed

ReferenceError: createSession is not defined #3085

wgarrido opened this issue Jul 22, 2020 · 10 comments
Assignees

Comments

@wgarrido
Copy link

wgarrido commented Jul 22, 2020

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
@perrin-lucas
Copy link

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",

@OkancanCosar
Copy link

@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

@cybersasi
Copy link

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

@kneth
Copy link
Contributor

kneth commented Aug 12, 2020

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

@deckyfx
Copy link

deckyfx commented Aug 13, 2020

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.

@deckyfx
Copy link

deckyfx commented Aug 14, 2020

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

@kneth
Copy link
Contributor

kneth commented Aug 14, 2020

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

@deckyfx
Copy link

deckyfx commented Aug 14, 2020

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

@kneth
Copy link
Contributor

kneth commented Aug 14, 2020

PR: #3135

@seyedasfar
Copy link

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants