question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] React Native Compatibility

See original GitHub issue

Hello, this is a new feature request!

I’m trying to get this library to work with React Native, and having a few issues. I’d love to work with the team on improving this if allowed so they can keep focusing on other priorities.

After implementing barrels, I discovered a couple of issues caused by a (IMHO very silly) React Native behaviour: if it sees any require('...') call, it tries to load the module in this require. It doesn’t matter whether this code is even inside if(false) or try { ... } catch { ...}. Since most of these require()s call built in Node stuff, and React Native runtime is not Node, it fails. See https://github.com/facebook/react-native/issues/5079 for reference.

So, it sees stuff from node_support/ and crypto_utils.ts, and shows an error for loading them, even if I’m not using these.

Each of these 2 can have different ways to handle.

crypto_utils.ts

In crypto_utils.ts, the line that breaks it is let crypto = require('crypto');. We can workaround the issue by doing something like:

const nodeRequire = require;
...
let crypto = nodeRequire('crypto');

This is sweet and easy, and if you approve, I’ll create a quick PR for it.

node_support

The contents of node_support is meant to be for Node. We can use the same workaround as above, but it’s not clean and quite silly actually.

If you approve, again, it might be a temporary solution.

Another temporary solution is to remove node_support from the main barrel. This way Node users will have to import from @openid/appauth/built/node_support (which has its own barrel), but having to import from built is quite silly.

The reason we have this issue is that TypeScript cannot have a base folder for looking for submodules except the package root - see https://github.com/Microsoft/TypeScript/issues/8305#issuecomment-343003095 as mentioned in https://github.com/openid/AppAuth-JS/pull/34#issuecomment-343003850

we can solve the built issue by compiling in-place instead of having src and built folders. Or, when publishing the package, implement a workflow where we copy the package.json file to built folder and publishing from inside that folder.

I can have a spin at this workflow (publishing from built but I cannot test it as I don’t have publish permissions. So, we either:

  • Move ts files to package root and compile in place
  • Change require calls in nnode_support for now
  • Remove nnode_support from the root barrel for now
  • If the team has capacity, implement the workflow that publishes from inside built

Happy to do pull request for any option you choose, or provide better clarification if this issue is a bit overwhelming.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mraiblecommented, Feb 21, 2018

I wrote an article for scotch.io last week that shows you how to use React Native App Auth to add authentication to a React Native application. Hope this helps! https://scotch.io/tutorials/build-a-react-native-app-and-authenticate-with-oauth-20

1reaction
mraiblecommented, Feb 23, 2018

@paulbrittain That’s a good question for Formidable, the folks that run React Native App Auth.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Requests | React Native - Canny
A framework for building native apps with React.
Read more >
React 18 & React Native
This page describes how to use React 18 with React Native using the React Native's New Architecture.
Read more >
Feature Request: Expo Plugin & Expo Documentation #1252
I have an error: "Native module RNShare tried to override RNShareModule. Check the getPackages() method is being created twice if this was your ......
Read more >
v5.xx - React Native Firebase
Simple Firebase integration for React Native with support for 10+ Firebase modules including Authentication, Analytics, Cloud Firestore and more.
Read more >
What Is React Native? Complex Guide for 2022 - Netguru
React Native is focused on building a great user experience for mobile devices, which makes it a suitable option for apps that require...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found