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

Error when authenticating user with token #2340

Closed
2 of 7 tasks
K9Developer opened this issue Nov 2, 2022 · 4 comments
Closed
2 of 7 tasks

Error when authenticating user with token #2340

K9Developer opened this issue Nov 2, 2022 · 4 comments
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects

Comments

@K9Developer
Copy link

Please avoid duplicates

Reproducible test case

Not sure

Please select the environment(s) that are relevant to your bug report

  • TypeScript
  • Enterprise
  • Browsers
  • Node
  • Deno

Version

octokit version: 2.0.10

imported: import { Octokit, App } from "octokit";

What happened?

I'm trying to use Octokit with react native, so I installed it, this step goes well, then imported, this one too goes well, but when running const octokit = new Octokit({ auth: token }); It errors and says:

Error: Unable to resolve module crypto from ... crypto could not be found within the project or in these directories:

What could be the problem?

(NodeJS version: 18.8.0)

Would you be interested in contributing a fix?

  • yes
@ghost ghost added this to Inbox in JS Nov 2, 2022
@gr2m
Copy link
Contributor

gr2m commented Nov 2, 2022

This is most likely a problem with webpack bundling, I think there were a few issues in the past about it. crypto should not make it into the browser build. Maybe this issue will help? gr2m/universal-github-app-jwt#38

@gr2m gr2m added the Type: Bug Something isn't working as documented label Nov 2, 2022
@ghost ghost moved this from Inbox to Bugs in JS Nov 2, 2022
@K9Developer
Copy link
Author

This is most likely a problem with webpack bundling, I think there were a few issues in the past about it. crypto should not make it into the browser build. Maybe this issue will help? gr2m/universal-github-app-jwt#38

Hi, I'm VERY new to react native... I'm not even sure I know what a web pack is. Could you maybe walk me a bit through it?

@gr2m
Copy link
Contributor

gr2m commented Nov 2, 2022

Unfortunately I don't have experience with React Native either. Webpack is used to bundle the code from octokit and its dependencies together with your React Native app's code, so that it can be run together on a device. But some dependencies such as https://github.com/gr2m/universal-github-app-jwt/ need to run different code for different environments (e.g. node or browsers). In your case, I assume React Native should get the browser code, but it bundles the Node code instead. When you want to run the app, you then get the error that the crypto module doesn't exist (which is a native Node module).

I'm sorry I can't help better. I'm sure other folks used Octokit with React Native in the past, maybe look for open source projects for reference?

You can also try and use @octokit/core instead of octokit, as it doesn't have the dependency on universal-github-app-jwt and hence shouldn't run into the particular problem you ran into

@gr2m gr2m added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Bug Something isn't working as documented labels Nov 2, 2022
@ghost ghost moved this from Bugs to Support in JS Nov 2, 2022
@K9Developer
Copy link
Author

K9Developer commented Nov 3, 2022

@gr2m Thanks, I will try using @octokit/core

EDIT: Thank you! It worked like a charm!!!

JS automation moved this from Support to Done Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
No open projects
JS
  
Done
Development

No branches or pull requests

3 participants