developit/redaxios

credentials not implemented for fetch in some environments such as cfw

einkoro opened this issue · 2 comments

When trying to use redaxios on CloudFlare Workers it will throw the following error:

 The 'credentials' field on 'RequestInitializerDict' is not implemented.

As the default is same-origin for credentials this could probably be worked around by not passing a credentials property when withCredentials is set to false:
https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials

In case you do not use this field and want a patch to make it go:

diff --git a/node_modules/redaxios/src/index.js b/node_modules/redaxios/src/index.js
index cca6534..a630e9a 100644
--- a/node_modules/redaxios/src/index.js
+++ b/node_modules/redaxios/src/index.js
@@ -199,7 +199,9 @@ function create(defaults) {
 			method: (_method || options.method || 'get').toUpperCase(),
 			body: data,
 			headers: deepMerge(options.headers, customHeaders, true),
-			credentials: options.withCredentials ? 'include' : _undefined
+			// Cloudflare Workers does not implement this and we do not need it
+			// https://github.com/developit/redaxios/issues/64
+			// credentials: options.withCredentials ? 'include' : _undefined
 		}).then((res) => {
 			for (const i in res) {
 				if (typeof res[i] != 'function') response[i] = res[i];

CloudFlare should really not be throwing here.