Skip to content

Commit

Permalink
fix: dynamically import module with native node dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Haynes committed Apr 18, 2023
1 parent 5b0deb4 commit ed68820
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/providers/src/fetch_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TypedError } from '@near-js/types';
import createError from 'http-errors';

import { exponentialBackoff } from './exponential-backoff';
import nodeFetch from './fetch';

const START_WAIT_TIME_MS = 1000;
const BACKOFF_MULTIPLIER = 1.5;
Expand All @@ -29,7 +28,11 @@ export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, js

const response = await exponentialBackoff(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, async () => {
try {
const response = await (global.fetch || nodeFetch)(connectionInfo.url, {
if (!global.fetch) {
global.fetch = (await import('./fetch')).default;
}

const response = await global.fetch(connectionInfo.url, {
method: json ? 'POST' : 'GET',
body: json ? json : undefined,
headers: { ...connectionInfo.headers, 'Content-Type': 'application/json' }
Expand Down

0 comments on commit ed68820

Please sign in to comment.