Skip to content

Commit c4cac60

Browse files
authored
fix: improve DISABLE_NODE_FETCH_NATIVE_WARN behavior (#128)
1 parent 2b5e3d4 commit c4cac60

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ You have two ways to do this:
8989
- Set the `FORCE_NODE_FETCH` environment variable before starting the application.
9090
- Import from `node-fetch-native/node`
9191

92+
## Disable runtime check
93+
94+
Once the `node-fetch-native/node` module is loaded, it pushes a log warning if the current runtime differs from the Node.js. Set the `DISABLE_NODE_FETCH_NATIVE_WARN` environment variable to turn this check off.
95+
9296
## Polyfill support
9397

9498
Using the polyfill method, we can ensure global fetch is available in the environment and all files. Natives are always preferred.

src/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ export {
2121

2222
const _forceNodeFetch = !!globalThis.process?.env?.FORCE_NODE_FETCH;
2323

24-
function _getFetch() {
25-
if (!_forceNodeFetch && globalThis.fetch) {
26-
return globalThis.fetch;
27-
}
28-
return _fetch;
29-
}
30-
31-
export const fetch = _getFetch();
24+
export const fetch = (!_forceNodeFetch && globalThis.fetch) || _fetch;
3225
export default fetch;
3326

3427
export const Blob = (!_forceNodeFetch && globalThis.Blob) || _Blob;

src/node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ checkNodeEnvironment();
2121
function checkNodeEnvironment() {
2222
if (
2323
!globalThis.process?.versions?.node &&
24-
!globalThis.process?.env.DISABLE_NODE_FETCH_NATIVE_WARN
24+
!globalThis.process?.env?.DISABLE_NODE_FETCH_NATIVE_WARN
2525
) {
2626
console.warn(
2727
"[node-fetch-native] Node.js compatible build of `node-fetch-native` is being used in a non-Node.js environment. Please make sure you are using proper export conditions or report this issue to https://github.com/unjs/node-fetch-native. You can set `process.env.DISABLE_NODE_FETCH_NATIVE_WARN` to disable this warning.",

0 commit comments

Comments
 (0)