Skip to content

Commit

Permalink
Replace cross-fetch with whatwg-fetch
Browse files Browse the repository at this point in the history
We import it conditionally anyway and cross-fetch has an issue where
it's used even in environments where fetch exists natively, see
lquixada/cross-fetch#138
  • Loading branch information
bahlo committed Jun 28, 2022
1 parent 2f3ecd8 commit c248da4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 87 deletions.
2 changes: 1 addition & 1 deletion __tests__/withAxiom.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withAxiom } from '../src/index';
import { NextApiRequest, NextApiResponse } from 'next';
import 'cross-fetch/polyfill';
import 'whatwg-fetch';
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server';

test('withAxiom(NextConfig)', async () => {
Expand Down
95 changes: 11 additions & 84 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"typescript": "^4.6.4"
},
"dependencies": {
"cross-fetch": "^3.1.5"
"whatwg-fetch": "^3.6.2"
}
}
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function sendLogs() {

try {
if (typeof fetch === 'undefined') {
const fetch = await require('cross-fetch');
const fetch = await require('whatwg-fetch');
await fetch(url, { body, method, keepalive });
} else if (isBrowser && navigator.sendBeacon) {
navigator.sendBeacon(url, body);
Expand Down

0 comments on commit c248da4

Please sign in to comment.