Oxygen deployment fails: Disallowed operation called within global scope
Before opening, please confirm:
- [x] I have searched for duplicate or closed issues and discussions.
- [x] I have read the guide for submitting bug reports.
- [x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Oxygen deployment
Describe the bug
Amplify seems to be using fetch or some other library globally that Cloudflare workers do not like and deployment fails.
Expected behavior
import { createUserPoolsTokenProvider } from 'aws-amplify/adapter-core'; should work
Reproduction steps
Install a remix app, import the line above in any project. Deploy to Shopify's Oxygen or any other cloudflare workers
Code Snippet
// Put your code below this line.
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
Hi @mciparelli ,
Thanks for reporting the issue. Can you let us know what is the actual failures? Can you share some failure logs and share some sample codes for us to try to reproduce the issue?
Fetch api is supported according to the doc - https://shopify.dev/docs/storefronts/headless/hydrogen/deployments/oxygen-runtime#web-crypto-api
Sure. This is the line that makes it fail: https://github.com/mciparelli/amplify-test/commit/0d39822097268a19e34f70c4e0f8f9f4ad1d0ad6#diff-d875722b54c99bae9491a58332631143d6d27319036bdf3be8e15e365d591978R3-R6
What I'm sharing there is the default Hydrogen template with just Amplify added as a dependency and loaded just that function that I know causes issues in Oxygen.
This is how Oxygen fails to deploy when adding a call to createUserPoolsTokenProvider:
Hi @mciparelli ,
Thanks for the information you shared. We will look into this issue and give you an update once we have any.
Hi @mciparelli ,
Thanks for the information you shared. We will look into this issue and give you an update once we have any.
Thanks to you for acknowledging. Unfortunately I'm not very familiar with the codebase and the eventual APIs that Oxygen may not like from Amplify , otherwise I would've submitted a PR. But hopefully it helps knowing that createUserPoolsTokenProvider is certainly one function that makes the deployment fail.
I have the same issue. I'm using Shopify Hydrogen template that uses Oxygen for deployments. This started happening after I added some new npm packages to my project:
- @mui/material
- @shapediver/viewer.session
- @shapediver/viewer.viewport
attaching complete log
C:\Users\SebastianMeckovski\repos\shopify-test\seb-storefront-test>npx shopify hydrogen deploy
? Select an environment to deploy to:
√ Production (handle: production, branch: main)
? Creating a deployment against Production (handle: production, branch: main)
Continue?
√ Yes, confirm deploy
Building project...
vite v5.4.14 building for production...
✓ 1790 modules transformed.
Generated an empty chunk: "sitemap._type._page_.xml_".
Generated an empty chunk: "account_.authorize".
Generated an empty chunk: "account_.logout".
Generated an empty chunk: "account._index".
Generated an empty chunk: "account_.login".
Generated an empty chunk: "discount._code".
Generated an empty chunk: "_sitemap.xml_".
Generated an empty chunk: "_robots.txt_".
Generated an empty chunk: "account._".
dist/client/oxygen.json 0.06 kB │ gzip: 0.07 kB
dist/client/assets/favicon-DZkC1E9c.svg 0.69 kB │ gzip: 0.35 kB
dist/client/.vite/manifest.json 12.66 kB │ gzip: 1.61 kB
dist/client/assets/reset-BKioPaen.css 1.23 kB │ gzip: 0.55 kB
dist/client/assets/app-DEOnVm4E.css 5.70 kB │ gzip: 1.63 kB
dist/client/assets/sitemap._type._page_.xml_-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/account_.authorize-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/account_.logout-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/account._index-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/account_.login-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/discount._code-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/_sitemap.xml_-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/_robots.txt_-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/account._-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/client/assets/cart._lines-C6d-v1ok.js 0.05 kB │ gzip: 0.07 kB
dist/client/assets/_-DtCUJE-g.js 0.05 kB │ gzip: 0.07 kB
dist/client/assets/search-DOeYwaXi.js 0.28 kB │ gzip: 0.23 kB
dist/client/assets/policies._index-4NTjGtIu.js 0.34 kB │ gzip: 0.24 kB
dist/client/assets/pages._handle-Dufxj4_B.js 0.36 kB │ gzip: 0.28 kB
dist/client/assets/cart-BPZU5HBZ.js 0.46 kB │ gzip: 0.32 kB
dist/client/assets/policies._handle-CdXLOhXE.js 0.47 kB │ gzip: 0.32 kB
dist/client/assets/variants-LfRANlwX.js 0.49 kB │ gzip: 0.33 kB
dist/client/assets/PaginatedResourceSection-CAN2lVQV.js 0.52 kB │ gzip: 0.31 kB
dist/client/assets/blogs._index-ycT3d-zn.js 0.55 kB │ gzip: 0.35 kB
dist/client/assets/blogs._blogHandle._articleHandle-DLsXo3sL.js 0.66 kB │ gzip: 0.44 kB
dist/client/assets/collections._index-BcgvASzr.js 0.81 kB │ gzip: 0.47 kB
dist/client/assets/account-O9XIh7jX.js 0.98 kB │ gzip: 0.50 kB
dist/client/assets/collections.all-BZdxbidm.js 1.00 kB │ gzip: 0.57 kB
dist/client/assets/blogs._blogHandle._index-gpMCdxKb.js 1.10 kB │ gzip: 0.61 kB
dist/client/assets/account.profile-CGR9g17i.js 1.15 kB │ gzip: 0.54 kB
dist/client/assets/collections._handle-DRC_Gn_y.js 1.22 kB │ gzip: 0.64 kB
dist/client/assets/account.orders._index-DYqUSuKT.js 1.29 kB │ gzip: 0.63 kB
dist/client/assets/ProductPrice-yICtx8Rz.js 1.29 kB │ gzip: 0.67 kB
dist/client/assets/_index-B5yAY_tm.js 1.32 kB │ gzip: 0.63 kB
dist/client/assets/log-seo-tags-TY72EQWZ-DCHH-_Gl.js 1.32 kB │ gzip: 0.69 kB
dist/client/assets/account.orders._id-DUwfvg1h.js 2.93 kB │ gzip: 0.94 kB
dist/client/assets/Money-BQP0wEmB.js 2.96 kB │ gzip: 1.27 kB
dist/client/assets/search-BopeWPBC.js 3.65 kB │ gzip: 1.35 kB
dist/client/assets/entry.client-B8_e452P.js 3.80 kB │ gzip: 1.45 kB
dist/client/assets/Image-B8MFQSH8.js 4.11 kB │ gzip: 1.66 kB
dist/client/assets/account.addresses-AltA_HjW.js 4.68 kB │ gzip: 1.34 kB
dist/client/assets/CartMain-Bru-83Yb.js 5.50 kB │ gzip: 1.95 kB
dist/client/assets/root-BVtF7EZK.js 13.30 kB │ gzip: 4.47 kB
dist/client/assets/index-D3WWKPkx.js 33.26 kB │ gzip: 11.67 kB
dist/client/assets/components-CrrQxqco.js 257.56 kB │ gzip: 82.90 kB
dist/client/assets/products._handle-Bpp4V6tF.js 3,970.81 kB │ gzip: 968.37 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 27.64s
vite v5.4.14 building SSR bundle for production...
✓ 1777 modules transformed.
dist/server/oxygen.json 0.06 kB
dist/server/assets/favicon-DZkC1E9c.svg 0.69 kB
dist/server/.vite/manifest.json 1.14 kB
dist/server/metafile.server.json 326.34 kB
dist/server/server-bundle-analyzer.html 393.33 kB
dist/server/assets/reset-BKioPaen.css 1.23 kB
dist/server/assets/app-DEOnVm4E.css 5.70 kB
dist/server/index.js 4,485.06 kB │ map: 18,270.18 kB
✓ built in 38.98s
│
├ node_modules/@shapediver/viewer.rendering-engine.rendering-engine-threejs/node_modules/three/build/three.cjs
722.8kb 16.5%
├ node_modules/@shapediver/viewer.rendering-engine.intersection-engine/node_modules/three/build/three.cjs
707.9kb 16.2%
├ node_modules/@shapediver/viewer.data-engine.geometry-engine/dist/gltfv2/draco/draco_decoder.js
620.3kb 14.2%
├ node_modules/@shapediver/viewer.rendering-engine.rendering-engine-threejs/node_modules/postprocessing/build/index.cjs 333.5kb 7.6%
├ node_modules/@shapediver/viewer.settings/node_modules/zod/lib/types.js
69.7kb 1.6%
├ node_modules/@shapediver/viewer.shared.types/node_modules/zod/lib/types.js
67.5kb 1.5%
├ node_modules/@shapediver/viewer.session-engine.session-engine/dist/implementation/SessionEngine.js
50.9kb 1.2%
├ node_modules/@shapediver/viewer.viewport/dist/implementation/ViewportApi.js
45.1kb 1.0%
├ node_modules/axios/dist/browser/axios.cjs
40.0kb 0.9%
├ node_modules/@shapediver/viewer.rendering-engine.rendering-engine-threejs/dist/loaders/MaterialLoader.js
35.2kb 0.8%
│
└─── Complete analysis: file://C:/Users/SebastianMeckovski/repos/shopify-test/seb-storefront-test/dist/server/server-bundle-analyzer.html ( file://C:/Users/SebastianMeckovski/repos/shopify-test/seb-storefront-test/dist/server/server-bundle-analyzer.html )
Deploying to Oxygen..
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Verifying deployment has been completed ...
Deployment failed, error: Uncaught Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler. https://developers.cloudflare.com/workers/runtime-apis/handlers/
at worker.mjs:1582:132436 in yqe
at worker.mjs:1582:135936 in create
at worker.mjs:1585:265414 in vnt
at worker.mjs:1585:271181 in Ant
at worker.mjs:1585:271272 in get instance
at worker.mjs:1591:980765
╭─ error ──────────────────────────────────────────────────────────────────────╮
│ │
│ Uncaught Error: Disallowed operation called within global scope. │
│ Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and │
│ generating random values are not allowed within global scope. To fix this │
│ error, perform this operation within a handler. │
│ https://developers.cloudflare.com/workers/runtime-apis/handlers/ │
│ at worker.mjs:1582:132436 in yqe │
│ at worker.mjs:1582:135936 in create │
│ at worker.mjs:1585:265414 in vnt │
│ at worker.mjs:1585:271181 in Ant │
│ at worker.mjs:1585:271272 in get instance │
│ at worker.mjs:1591:980765 │
│ │
│ │
│ Retrying the deployment may succeed. │
│ │
│ Next steps │
│ • If the issue persists, please check the Shopify status page [1] for │
│ any known issues. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Verifying deployment has been completed ...
@sebastian-meckovski, thanks for letting us know. We're still investigating this issue, and we'll make an update here as soon as we have one.
Hey @mciparelli, thanks again for reporting this and providing the detailed information. I was able to reproduce in a Cloudflare Worker and following the code path I can see we have some incompatible operations for this runtime in the global scope.
I will discuss with the team how we can best support this use case. We'll follow up shortly.
Hey @mciparelli, thanks again for reporting this and providing the detailed information. I was able to reproduce in a Cloudflare Worker and following the code path I can see we have some incompatible operations for this runtime in the global scope.
I will discuss with the team how we can best support this use case. We'll follow up shortly.
Appreciate the team looking into this!
Hi @mciparelli
We have found what's likely to be the cause of this issue, however there's no easy workaround for it yet. We'll keep you post here has we look into a potential fix.
It's worths to mention that CF worker is not a runtime we officially support or test against. We will also keep you post if this is something we will offer official support for.
Hi @mciparelli
We have found what's likely to be the cause of this issue, however there's no easy workaround for it yet. We'll keep you post here has we look into a potential fix.
It's worths to mention that CF worker is not a runtime we officially support or test against. We will also keep you post if this is something we will offer official support for.
Alright that makes sense, thank you for looking into it anyway, I appreciate it!
Is there any update on this, we are getting the same error. We import a private npm package in our app which exports a react component, and it causes the issue, the only way to fix it is to import the library inside useEffect but that's not the best workaround as we lose SSR option.
Hey @Alopwer, we released a fix for this issue in this version. can you try to update to the latest version and check if this fixes the issue? Thanks!