Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native and Https Agent

Is possible use HTTPS Agent in React Native app?

My code right now is:

import axios from 'axios';
import ip from './ip';

import https from 'https';

const httpsAgent = new https.Agent({rejectUnauthorized: false});

const api = axios.create({
    baseURL: `${ip}/api`,
    httpsAgent,
});

export default api;

But show the follow Error:

ExceptionsManager.js:76 Error: InternalError Metro has encountered an error: While trying to resolve module https from file /mobile/src/services/api.js, the package /mobile/node_modules/https/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/mobile/node_modules/https/index.js. Indeed, none of these files exist:

  • /mobile/node_modules/https/index.js(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  • /mobile/node_modules/https/index.js/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
like image 546
Mateus Alves de Oliveira Avatar asked Jun 06 '20 13:06

Mateus Alves de Oliveira


1 Answers

Https is a Node Core Module. Have you tried using rn-nodefy? It makes your React Native application able to use Node Core Modules.

like image 160
Sergio Costa Avatar answered Sep 17 '22 10:09

Sergio Costa