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

🐛 BUG: global is not defined while using aws-sdk #3627

Closed
Codename-404 opened this issue Jul 18, 2023 · 4 comments
Closed

🐛 BUG: global is not defined while using aws-sdk #3627

Codename-404 opened this issue Jul 18, 2023 · 4 comments
Labels
awaiting reporter response Needs clarification or followup from OP bug Something that isn't working

Comments

@Codename-404
Copy link

Codename-404 commented Jul 18, 2023

Which Cloudflare product(s) does this pertain to?

Workers Runtime, Wrangler core

What version(s) of the tool(s) are you using?

"wrangler": "^3.0.0", "aws-sdk": "^2.1416.0"

What version of Node are you using?

v18.16.0

What operating system are you using?

Mac

Describe the Bug

I get the following error when I try to deploy the code to worker from my local environment. This issue only occurs when using 'aws-sdk'

Uncaught ReferenceError: global is not defined
at worker.js:12285:35 in node_modules/aws-sdk/node_modules/buffer/index.js
at worker.js:3:50 in __require
at worker.js:13745:19 in node_modules/aws-sdk/lib/browserHashUtils.js
at worker.js:3:50 in __require
at worker.js:13788:21 in node_modules/aws-sdk/lib/browserHmac.js
at worker.js:3:50 in __require
at worker.js:14303:16 in node_modules/aws-sdk/lib/browserCryptoLib.js
at worker.js:3:50 in __require
at worker.js:17600:23 in node_modules/aws-sdk/lib/browser_loader.js
at worker.js:3:50 in __require
[code: 10021]

Please provide a link to a minimal reproduction

It's happening just by installing aws-sdk and importing it. "aws-sdk": "^2.1416.0". Even if it's a hello world project. Just install and import aws-sdk to index.js or wrangler.js. And once you try to deploy, it fails with these errors

Please provide any relevant error logs

Uncaught ReferenceError: global is not defined
at worker.js:12285:35 in node_modules/aws-sdk/node_modules/buffer/index.js
at worker.js:3:50 in __require
at worker.js:13745:19 in node_modules/aws-sdk/lib/browserHashUtils.js
at worker.js:3:50 in __require
at worker.js:13788:21 in node_modules/aws-sdk/lib/browserHmac.js
at worker.js:3:50 in __require
at worker.js:14303:16 in node_modules/aws-sdk/lib/browserCryptoLib.js
at worker.js:3:50 in __require
at worker.js:17600:23 in node_modules/aws-sdk/lib/browser_loader.js
at worker.js:3:50 in __require
[code: 10021]

@Codename-404 Codename-404 added the bug Something that isn't working label Jul 18, 2023
@mrbbot
Copy link
Contributor

mrbbot commented Oct 9, 2023

Hey! 👋 Apologies for the delayed response? Does adding globalThis.global = globalThis to the top of your worker's entrypoint fix this for you?

@mrbbot mrbbot added the awaiting reporter response Needs clarification or followup from OP label Oct 9, 2023
@lrapoport-cf
Copy link
Contributor

hi @Codename-404 :) we haven’t heard back so we will close the issue for now. however, if this is still an issue and @mrbbot 's suggestion doesn't fix it, please feel free to re-open it. thanks!

@alex-h-strachan
Copy link

alex-h-strachan commented Nov 28, 2023

Hi I have the same problem and adding globalThis.global = globalThis to my entrypoint did not resolve this.

What's worse is wrangler deploy is the command failing so I can't even inspect what it was trying to deploy to fix it.

[2023-11-28T03:26:28Z]   Uncaught ReferenceError: global is not defined
[2023-11-28T03:26:28Z]     at index.js:13833:35 in node_modules/buffer/index.js
[2023-11-28T03:26:28Z]     at index.js:11:50 in __require
[2023-11-28T03:26:28Z]     at index.js:15296:19 in node_modules/aws-sdk/lib/browserHashUtils.js
[2023-11-28T03:26:28Z]     at index.js:11:50 in __require
[2023-11-28T03:26:28Z]     at index.js:15340:21 in node_modules/aws-sdk/lib/browserHmac.js
[2023-11-28T03:26:28Z]     at index.js:11:50 in __require
[2023-11-28T03:26:28Z]     at index.js:15859:16 in node_modules/aws-sdk/lib/browserCryptoLib.js
[2023-11-28T03:26:28Z]     at index.js:11:50 in __require
[2023-11-28T03:26:28Z]     at index.js:19516:23 in node_modules/aws-sdk/lib/browser_loader.js
[2023-11-28T03:26:28Z]     at index.js:11:50 in __require
[2023-11-28T03:26:28Z]    [code: 10021]
[2023-11-28T03:26:28Z]
[2023-11-28T03:26:28Z]

@mrbbot
Copy link
Contributor

mrbbot commented Nov 28, 2023

Hey @alex-h-strachan! You should be able to use the wrangler build command to inspect the deployed code. Make sure you're defining global before importing any modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reporter response Needs clarification or followup from OP bug Something that isn't working
Projects
None yet
Development

No branches or pull requests

4 participants