Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js support? #22

Open
march08 opened this issue Jul 28, 2020 · 13 comments · May be fixed by #43
Open

Node.js support? #22

march08 opened this issue Jul 28, 2020 · 13 comments · May be fixed by #43

Comments

@march08
Copy link

march08 commented Jul 28, 2020

works well in the browser however there are some differences in the WebAPI vs node. Are you planning to add SSR support as well? Thanks

@mhart
Copy link
Owner

mhart commented Jul 28, 2020

@march08 I'm not sure what you mean? Server Side Rendering is orthogonal to a library like this. Can you be more specific?

@march08
Copy link
Author

march08 commented Jul 28, 2020

@march08 I'm not sure what you mean? Server Side Rendering is orthogonal to a library like this. Can you be more specific?

For example, crypto.subtle doesn't exist on server (node) but web crypto api only.
headers.keys is undefined on server as well.

@mhart
Copy link
Owner

mhart commented Jul 28, 2020

Right, Node.js doesn't support fetch (you could try out https://github.com/node-fetch/node-fetch ) or crypto.subtle (you could try out https://github.com/PeculiarVentures/node-webcrypto-ossl)

@march08
Copy link
Author

march08 commented Jul 28, 2020

fetch can be added with isomorphic-fetch but Headers.keys() doesn't work (available only via Web API). In the end I had to rewrite the code to make it work )

@mhart
Copy link
Owner

mhart commented Jul 28, 2020

Well that must be a bug with that library, it's supported in node-fetch:

https://github.com/node-fetch/node-fetch/blob/ca50c22e3410ee288a7b4a8a89384d6df95ae3b6/%40types/index.d.ts#L46

@rafaelnogueira1
Copy link

@march08 how did you solve this? 'm using nextjs and i stuck in this problem.

@rafaelnogueira1
Copy link

In the end i end up change to use aws4-axios to solve my problem.

@half2me
Copy link

half2me commented Aug 27, 2021

@mhart just adding to this issue. First of all, huge thanks for this. I'm trying to break away from the bloated and buggy Amplify library for my SvelteKit app.
In my use-case SSR runs on cloudflare workers, so SubtleCrypto is available, but when testing locally with Node.js I need to disable SSR to use this libray, even though I have nodejs 16.
From what I can see, SubtleCrypto is available on Node.js as well: https://nodejs.org/api/webcrypto.html#webcrypto_class_subtlecrypto
It would be really useful if this library could be used on both browser and node.js

@badalya1
Copy link

@march08 You are probably looking for aws4 if you want to use it in node.

@half2me
Copy link

half2me commented May 19, 2022

@badalya1 well I want to use it on browser and cf workers in production, but in node just for testing.

@mhart mhart changed the title SSR support? Node.js support? Oct 6, 2022
@mhart
Copy link
Owner

mhart commented Oct 6, 2022

Changing this to be a Node.js-support specific issue. The ability to use this locally should be supported by workerd and I assume Deno as well (though haven't checked).

If anyone knows what the specific issues with current Node.js support of these APIs are, let me know!

@n1ru4l
Copy link

n1ru4l commented Nov 29, 2022

I achieved Node.js support with @whatwg-node/fetch, we run it on both Node.js and Cloudflare Workers.

diff --git a/dist/aws4fetch.esm.js b/dist/aws4fetch.esm.js
index 9a47c421432cb8dc9f92a07a49fd46d2c00c57f3..f853ca70741083272fea7e57b405c9920402be3e 100644
--- a/dist/aws4fetch.esm.js
+++ b/dist/aws4fetch.esm.js
@@ -1,3 +1,5 @@
+import { fetch, Request, Headers, crypto, TextEncoder } from '@whatwg-node/fetch';
+
 /**
  * @license MIT <https://opensource.org/licenses/MIT>
  * @copyright Michael Hart 2022
diff --git a/dist/aws4fetch.esm.mjs b/dist/aws4fetch.esm.mjs
index 9a47c421432cb8dc9f92a07a49fd46d2c00c57f3..f853ca70741083272fea7e57b405c9920402be3e 100644
--- a/dist/aws4fetch.esm.mjs
+++ b/dist/aws4fetch.esm.mjs
@@ -1,3 +1,5 @@
+import { fetch, Request, Headers, crypto, TextEncoder } from '@whatwg-node/fetch';
+
 /**
  * @license MIT <https://opensource.org/licenses/MIT>
  * @copyright Michael Hart 2022
  * 

@0x1abin
Copy link

0x1abin commented Aug 22, 2023

It works on both Node v20.5.1 and Cloudflare Worker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants