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

Cannot read property 'getCurrentUserAsync' of undefined #1060

Closed
abhinavkhajuria opened this issue Jul 21, 2019 · 10 comments
Closed

Cannot read property 'getCurrentUserAsync' of undefined #1060

abhinavkhajuria opened this issue Jul 21, 2019 · 10 comments

Comments

@abhinavkhajuria
Copy link

abhinavkhajuria commented Jul 21, 2019

Issue

  1. I am unable to debug in exponent due to error "Cannot read property 'getCurrentUserAsync' of undefined".

Software versions

  • React-Native VS Code extension version: 0.10.2
  • VSCode version: 1.35.1
  • OS platform and version: Ubuntu 16.04, Linux x64 4.4.0-154-generic
  • NodeJS version: 10.2.0
  • React Native version: 0.59.8
  • Expo SDK version (include if relevant):33.0.0

Outputs (Include if relevant)

  • Output of the Debug Console (View -> Toggle Debug Console):
OS: linux x64
Adapter node: v10.2.0 x64
vscode-chrome-debug-core: 6.7.46
Could not debug. Cannot read property 'getCurrentUserAsync' of undefined
  • Output of the React-Native output channel (View -> Toggle Output -> Select React-Native in ListBox):
[Info] Making sure your project uses the correct dependencies for Expo. This may take a while...

Checking if this is Expo app......
[Info] Starting Packager

┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  Running Metro Bundler on port 8081.                                         │
│                                                                              │
│  Keep Metro running while developing on any JS projects. Feel free to        │
│  close this tab and run your own Metro instance if you prefer.               │
│                                                                              │
│  https://github.com/facebook/react-native                                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Looking for JS files in
   /home/dj/Desktop/Myapp 

[Info] Packager started.

[Info] Prewarming bundle cache. This may take a while ...

[Info] Building and running application.

[Error] TypeError: Cannot read property 'getCurrentUserAsync' of undefined
  • Output of the Developer Tools console (Help -> Toggle Developer Tools -> Select Console tab):
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:238 [Extension Host] rejected promise not handled within 1 second: TypeError: Cannot read property 'getCurrentUserAsync' of undefined
t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:238
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:238 [Extension Host] stack trace: TypeError: Cannot read property 'getCurrentUserAsync' of undefined
    at getPackage.then (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/src/extension/exponent/xdlInterface.js:62:33)
    at _fulfilled (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:834:54)
    at Promise.then.Q.nextTick.self.promiseDispatch.done (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:796:13)
    at /home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:857:14
    at runSingle (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:137:13)
    at flush (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:61:11)
t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:238
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:1406   ERR Cannot read property 'getCurrentUserAsync' of undefined: TypeError: Cannot read property 'getCurrentUserAsync' of undefined
    at getPackage.then (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/src/extension/exponent/xdlInterface.js:62:33)
    at _fulfilled (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:834:54)
    at Promise.then.Q.nextTick.self.promiseDispatch.done (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:796:13)
    at /home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:857:14
    at runSingle (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:137:13)
    at flush (/home/dj/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2/node_modules/q/q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:61:11)
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:238 [Extension Host] (node:7564) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:238
@serkanz
Copy link

serkanz commented Jul 22, 2019

Same problem occurs with the configuration below :

VSCODE Version: 1.36.1
React-Native VS Code extension version: 0.10.2
Node.js: 10.15.1
OS: Win32 x64
Expo: 3.0.2

Update : Reverting back to 0.10.0 didn't solve the problem. Other IDE functions are working properly

@ruslan-bikkinin
Copy link
Contributor

Hi guys, thanks for letting us know. It seems to be an @expo/xdl package regression: expo/expo-cli#864. To workaround it simply reinstall @expo/xdl package in extension directory:

  • Open extension directory in terminal: cd YOUR_HOME_DIRECTORY/.vscode/extensions/msjsdiag.vscode-react-native-0.10.2
  • Uninstall @expo/xdl: npm uni --no-save @expo/xdl
  • Install @expo/xdl@56.0.0: npm i --no-save @expo/xdl@56.0.0

When the original issue will be resolved and expo will release a patch, just reinstall the extension and problem will go away automatically.

@abhinavkhajuria
Copy link
Author

Thanks, @ruslan-bikkinin, it worked for me.

@serkanz
Copy link

serkanz commented Jul 23, 2019

thanks @ruslan-bikkinin , that worked like a charm.

@akash-dubey-kranti
Copy link

Thanks, @ruslan-bikkinin, it worked. You saved my day.

@yosef-abraham
Copy link

thanks, helped a lot

garfieldnate added a commit to garfieldnate/flashcards that referenced this issue Aug 2, 2019
What an adventure today was! I spent the whole day, minus lunch and a short
meeting with Rupesh, debugging this. If you want to know how long that was,
check the commit timestamp :) I did learn how to debug from VS code, which is
cool, although apparently I may have to restart my computer once in a while T_T

Here's a chronological list of everything I tried or investigated and the notes
I wrote while doing that:

- going back to previous commits and redoing some work
- resetting DB
- resetting device
- pushing data from app and trying to reload it (pushing only works sometimes)
- checking that other webapps are not running (shouldn't matter, but I'm desperate)
- Updating dependencies (including Expo and even node!)
- pouchdb-adapter-http's fetchJSON keeps returning this stuff:
`{"\_40":0,"\_65":0,"\_55":null,"\_72":null}` (oh wait, that's what a Promise
looks like for some reason!). Actually fetchJSON returns stuff correctly.
Goes to http://localhost:5984/flashcards/_changes?style=all_docs&since=0&limit=100,
gets back big thing with all flashcards.
- made pouchdb adapters same version as RxDB's pouchdb core dependency
- changing order of RxDB.plugin calls
- had to downgrade XDL for debugging to work in VSCode. See
microsoft/vscode-react-native#1060
- debugging (at least with VS code plugin) is difficult; expo app freezes when
I try to restart debugging
- I've been having trouble with my headphones giving crappy sound over bluetooth
lately. Figured out that closing the home screen in the Simulator actually brings
the sound quality back! Although it's still stronger in one ear. It's extra
weird because you can't even turn bluetooth connections in the simulator.
- do `yarn add pouchdb-debug` and then find "comment in to debug" in
RxDB/pouch-db.js. Did nothing.
- Copied that section into my own code and now I can see PouchDB debug statements!

    const pouchdbDebug = require('pouchdb-debug');
    RxDB.plugin(pouchdbDebug);
    RxDB.PouchDB.debug.enable('*');

- Apparently revs can be missing in change sequences, so patch RxDB/utils.js:

    export function getHeightOfRevision(revString) {
      if (!revString) {
        return 0;
      }
      const first = revString.split('-')[0];
      return parseInt(first);
    }

- Set process.browser = true globally to make sure pouchdb-adapter-http uses response.blob() instead of .buffer()
- Sent two PR's regarding these issues
- Man, you have to be really careful with the vscode RN/Expo debugger. I ended
up spawning lots of sleeping/waiting processes that I couldn't kill, and then
debugging just wouldn't work anymore, I think because all the metro packagers
were trying to connect to the client and do the same thing. Just had to restart
my computer T_T
- Getting  `Creating blobs from 'ArrayBuffer' and 'ArrayBufferView' are not
supported`, but can't get the call stack. Annoying pouchdb reports this as not
found instead of error :( The attachments are definitely being found.
- Tracked message to react-native/Libraries/Blob/BlobManager.js in the Blob constructor.
- calling PouchDB's getAttachment() with options = { binary: false } gets ignored because PouchDB tries to do the most "efficient" thing on its own. Gets set to "true" in node_modules/pouchdb-core/lib/index.js before it gets to pouchdb-adapter-asyncstorage/src/get_attachment.js, where it wreaks havoc. Have to patch it to `false` in that file or... find out how to make it always false in PouchDB somewhere.
- Can't patch it in PouchDB because the docs explicitly say that `getAttachment()` always returns a blob. I don't think they will be happy being asked to change that, because then all of their plugins would have to support non-binary queries :( But now the plugins all have to assume that the `binary` option actually means "binary if possible otherwise not". adapter-asyncstorage actually uses this option, but it can't have ever worked! The docs even say that it is supposed to be for RN, so why...?
- URL.createObjectURL(blob) doesn't work in RN; changed to `'data:image/png;base64,' + blob`
- `FileReader.readAsArrayBuffer` polyfill is still required for the HTTP attachment pulling

***

Quick overview of the fixes we have:

PR's sent:

1. RxDB doesn't handle missing revision IDs: pubkey/rxdb#1347
2. PouchDB's feature detection logic not working for HN: pouchdb/pouchdb#7862

Local patches:

1. Fix for RxDB not handling missing revision IDs
2. Fix for pouchdb-adapter-asyncstorage trying to respect `options.binary`,
(PouchDB always sets to `true`, must be `false` to prevent errors in RN).

The PouchDB feature detection logic is also fixed by simply setting
`process.browser = true;` for now, since it was even easier than a patch and
should be temporary.

Finally, we also keep the polyfill for `FileReader.prototype.readAsArrayBuffer`,
which is needed for reading the binary attachment data from the server.

***

So at the end of the day, I have two GH tickets and two local patches. It may be better to open a third regarding the hardcoding of `options.binary` to `true` in PouchDB.core's `getAttachments()`, but I wouldn't now how to solve it. I just know it's problematic. In the longer wrong I would like both PR's accepted, and both patches removed (one fixed by the PR, the other by switching to an RN sqlite adapter).

What a night!
garfieldnate added a commit to garfieldnate/flashcards that referenced this issue Aug 3, 2019
What an adventure today was! I spent the whole day, minus lunch and a short
meeting with Rupesh, debugging this. If you want to know how long that was,
check the commit timestamp :) I did learn how to debug from VS code, which is
cool, although apparently I may have to restart my computer once in a while T_T

Here's a chronological list of everything I tried or investigated and the notes
I wrote while doing that:

- going back to previous commits and redoing some work
- resetting DB
- resetting device
- pushing data from app and trying to reload it (pushing only works sometimes)
- checking that other webapps are not running (shouldn't matter, but I'm desperate)
- Updating dependencies (including Expo and even node!)
- pouchdb-adapter-http's fetchJSON keeps returning this stuff:
`{"\_40":0,"\_65":0,"\_55":null,"\_72":null}` (oh wait, that's what a Promise
looks like for some reason!). Actually fetchJSON returns stuff correctly.
Goes to http://localhost:5984/flashcards/_changes?style=all_docs&since=0&limit=100,
gets back big thing with all flashcards.
- made pouchdb adapters same version as RxDB's pouchdb core dependency
- changing order of RxDB.plugin calls
- had to downgrade XDL for debugging to work in VSCode. See
microsoft/vscode-react-native#1060
- debugging (at least with VS code plugin) is difficult; expo app freezes when
I try to restart debugging
- I've been having trouble with my headphones giving crappy sound over bluetooth
lately. Figured out that closing the home screen in the Simulator actually brings
the sound quality back! Although it's still stronger in one ear. It's extra
weird because you can't even turn bluetooth connections in the simulator.
- do `yarn add pouchdb-debug` and then find "comment in to debug" in
RxDB/pouch-db.js. Did nothing.
- Copied that section into my own code and now I can see PouchDB debug statements!

    const pouchdbDebug = require('pouchdb-debug');
    RxDB.plugin(pouchdbDebug);
    RxDB.PouchDB.debug.enable('*');

- Apparently revs can be missing in change sequences, so patch RxDB/utils.js:

    export function getHeightOfRevision(revString) {
      if (!revString) {
        return 0;
      }
      const first = revString.split('-')[0];
      return parseInt(first);
    }

- Set process.browser = true globally to make sure pouchdb-adapter-http uses response.blob() instead of .buffer()
- Sent two PR's regarding these issues
- Man, you have to be really careful with the vscode RN/Expo debugger. I ended
up spawning lots of sleeping/waiting processes that I couldn't kill, and then
debugging just wouldn't work anymore, I think because all the metro packagers
were trying to connect to the client and do the same thing. Just had to restart
my computer T_T
- Getting  `Creating blobs from 'ArrayBuffer' and 'ArrayBufferView' are not
supported`, but can't get the call stack. Annoying pouchdb reports this as not
found instead of error :( The attachments are definitely being found.
- Tracked message to react-native/Libraries/Blob/BlobManager.js in the Blob constructor.
- calling PouchDB's getAttachment() with options = { binary: false } gets ignored because PouchDB tries to do the most "efficient" thing on its own. Gets set to "true" in node_modules/pouchdb-core/lib/index.js before it gets to pouchdb-adapter-asyncstorage/src/get_attachment.js, where it wreaks havoc. Have to patch it to `false` in that file or... find out how to make it always false in PouchDB somewhere.
- The other error that must be avoided in pouchdb-adapter-http is
`Cannot set property type of #<Blob> which has only a getter`. I guess
`Blob.type` is readonly in RN.
- Can't patch it in PouchDB because the docs explicitly say that `getAttachment()` always returns a blob. I don't think they will be happy being asked to change that, because then all of their plugins would have to support non-binary queries :( But now the plugins all have to assume that the `binary` option actually means "binary if possible otherwise not". adapter-asyncstorage actually uses this option, but it can't have ever worked! The docs even say that it is supposed to be for RN, so why...?
- URL.createObjectURL(blob) doesn't work in RN; changed to `'data:image/png;base64,' + blob`
- `FileReader.readAsArrayBuffer` polyfill is still required for the HTTP attachment pulling

***

Quick overview of the fixes we have:

PR's sent:

1. RxDB doesn't handle missing revision IDs: pubkey/rxdb#1347
2. PouchDB's feature detection logic not working for HN: pouchdb/pouchdb#7862

Local patches:

1. Fix for RxDB not handling missing revision IDs
2. Fix for pouchdb-adapter-asyncstorage trying to respect `options.binary`,
(PouchDB always sets to `true`, must be `false` to prevent errors in RN).

The PouchDB feature detection logic is also fixed by simply setting
`process.browser = true;` for now, since it was even easier than a patch and
should be temporary.

Finally, we also keep the polyfill for `FileReader.prototype.readAsArrayBuffer`,
which is needed for reading the binary attachment data from the server.

***

So at the end of the day, I have two GH tickets and two local patches. It may be better to open a third regarding the hardcoding of `options.binary` to `true` in PouchDB.core's `getAttachments()`, but I wouldn't now how to solve it. I just know it's problematic. In the longer wrong I would like both PR's accepted, and both patches removed (one fixed by the PR, the other by switching to an RN sqlite adapter).

What a night!
@olegMarin
Copy link

it really worked for me!

@jaikme
Copy link

jaikme commented Aug 27, 2019

@ruslan-bikkinin answer works, but you will need repeat the process if the vscode-react-native gets updated, mine now is msjsdiag.vscode-react-native-0.11.0

@ruslan-bikkinin
Copy link
Contributor

@jaikme unfortunately, yes. We can't do much about it because this is Expo issue. If you want to get it resolved quicker, I'd suggest to go to the issue page and vote for it/leave a comment.

@orefors
Copy link

orefors commented Sep 7, 2019

So, I apply the @expo/xdl downgrade workaround suggested by @ruslan-bikkinin above, which gets rid of the get "Cannot read property 'getCurrentUserAsync' of undefined" and everything appears to be good. However, when I try to run the app in my android Expo client app, I get a message that the "Packager not running at...." and it all comes to a stop. Running VS code1.38 with React Native Tools 0.11 but have also tried earlier versions with the same result. Any ideas anyone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants