React Native and Https Agent

Viewed 3203

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)
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.

Related