Skip to content

Uncaught Error: Disallowed operation called within global scope. #2805

Closed

Description

@sebastian-meckovski

What is the location of your example repository?

https://github.com/sebastian-meckovski/shopfiy-shapediver-poc/tree/debug-branch

Which package or tool is having this issue?

Not sure if this is Hydrogen package or Oxygen deployment issue

What version of that package or tool are you using?

2025.1.2

What version of Remix are you using?

2.0.11

Steps to Reproduce

  1. Scaffold Shopify Hydrogen project using npm create @shopify/hydrogen@latest
  2. Install NPM package @shapediver/viewer.session
  3. Update vite.config.ts optimizeDeps to include @shapediver/viewer.session
  4. Update entry.server.tsx security policy
    connectSrc: [
      'https://sdr8euc1.eu-central-1.shapediver.com'
    ]
  1. Run this code on products.$handle.tsx
        const session = await createSession({
          ticket:
            'ba390f092896eaf776e6259f607aeb8946ac1359671be86608452f0718ef7311da4b9ba9d6eff6c841415ca7927ef211a018ba90591a32b75a2d578bd9e613dc1d00e9387ba90e69c809ac6f7f7f923cea54ea061dba656144fd788b65173466f3a8a20fd9429a-2511deeda86828ddaa2386dca43e3bea',
          modelViewUrl: 'https://sdr8euc1.eu-central-1.shapediver.com',
        });

This works locally
6. Deploy to Oxygen using npx shopify hydrogen deploy

Expected Behavior

Should deploy successfully and work the same way it works on localhost:3000

Actual Behavior

C:\Users\some-user\repos\shopfiy-shapediver-poc>npx shopify hydrogen deploy
?  Select an environment to deploy to:
√  Preview (handle: preview)

Building project...
vite v5.4.14 building for production...
✓ 1483 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.62 kB │ gzip:   1.61 kB
dist/client/assets/reset-BKioPaen.css                                1.23 kB │ gzip:   0.55 kB
dist/client/assets/app-CFDV3s0Q.css                                  5.60 kB │ gzip:   1.60 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-B0rRlrqG.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-DUfPxs00.js              0.52 kB │ gzip:   0.31 kB
dist/client/assets/blogs._index-gOafM-r5.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-BAUK3q39.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-sF9ztxmC.js                       1.00 kB │ gzip:   0.57 kB
dist/client/assets/blogs._blogHandle._index-BVPo3hTv.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-DUxuXaJ7.js                   1.22 kB │ gzip:   0.64 kB
dist/client/assets/account.orders._index-8pHtJ2F2.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-D1k2kULh.js                    2.88 kB │ gzip:   0.91 kB
dist/client/assets/Money-BQP0wEmB.js                                 2.96 kB │ gzip:   1.27 kB
dist/client/assets/search-DIb3-BTW.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-GvDYCxeL.js                              5.50 kB │ gzip:   1.95 kB
dist/client/assets/root-CAiD-aRw.js                                 13.30 kB │ gzip:   4.46 kB
dist/client/assets/index-D9r4M8R3.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-DdbnxwjH.js                  1,893.77 kB │ gzip: 432.47 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 49.28s

vite v5.4.14 building SSR bundle for production...
✓ 1470 modules transformed.
dist/server/oxygen.json                      0.06 kB
dist/server/assets/favicon-DZkC1E9c.svg      0.69 kB
dist/server/.vite/manifest.json              1.10 kB
dist/server/metafile.server.json           315.60 kB
dist/server/server-bundle-analyzer.html    377.26 kB
dist/server/assets/reset-BKioPaen.css        1.23 kB
dist/server/assets/app-CFDV3s0Q.css          5.60 kB
dist/server/index.js                     2,406.60 kB │ map: 11,897.56 kB
✓ built in 1m 7s
    │
    ├ node_modules/@shapediver/viewer.data-engine.geometry-engine/dist/gltfv2/draco/draco_decoder.js
                                       620.3kb   26.4%
    ├ node_modules/@shapediver/viewer.settings/node_modules/zod/lib/types.js
                                        69.7kb    3.0%
    ├ node_modules/@shapediver/viewer.shared.types/node_modules/zod/lib/types.js
                                        67.5kb    2.9%
    ├ node_modules/@shapediver/viewer.session-engine.session-engine/dist/implementation/SessionEngine.js
                                        50.9kb    2.2%
    ├ node_modules/@shapediver/sdk.geometry-api-sdk-core/node_modules/axios/dist/browser/axios.cjs
                                        41.9kb    1.8%
    ├ node_modules/@shapediver/sdk.sdtf-v1/node_modules/axios/dist/browser/axios.cjs
                                        39.7kb    1.7%
    ├ node_modules/decimal.js/decimal.js
                                        31.5kb    1.3%
    ├ node_modules/dompurify/dist/purify.js
                                        21.4kb    0.9%
    ├ node_modules/@shapediver/viewer.shared.types/dist/implementation/material/MaterialMultiPointData.js
                                        20.9kb    0.9%
    ├ node_modules/@shapediver/viewer.data-engine.gltf-converter/dist/GLTFConverter.js
                                        20.5kb    0.9%
    │
    └─── Complete analysis: file://C:/Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/dist/server/server-bundle-analyzer.html ( file://C:/Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/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:1587:123667 in t3e
  at worker.mjs:1587:127162 in create
  at worker.mjs:1590:265308 in YPe
  at worker.mjs:1590:271075 in QPe
  at worker.mjs:1590:271166 in get instance
  at worker.mjs:1601:899454

╭─ 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:1587:123667 in t3e                                          │
│    at worker.mjs:1587:127162 in create                                       │
│    at worker.mjs:1590:265308 in YPe                                          │
│    at worker.mjs:1590:271075 in QPe                                          │
│    at worker.mjs:1590:271166 in get instance                                 │
│    at worker.mjs:1601:899454                                                 │
│                                                                              │
│                                                                              │
│  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 ...

Activity

  1. blittle commented on Mar 24, 2025

    @blittle
    Contributor

    @sebastian-meckovski I get a 500 error attempting to follow the steps you provided:

    Error: Embedding check failed
        at HttpClient.convertError (/Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:6731:17)
        at SessionEngine.<anonymous> (/Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:114976:38)
        at Generator.next (<anonymous>)
        at /Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:113505:71
        at new Promise (<anonymous>)
        at __awaiter (/Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:113487:14)
        at SessionEngine.handleError (/Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:114935:16)
        at SessionEngine.<anonymous> (/Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:114180:24)
        at Generator.throw (<anonymous>)
        at rejected (/Users/blittle/dev/test/node_modules/.vite/deps_ssr/@shapediver_viewer__session.js:113497:36)
    

    What happens if you run the preview locally? npm run preview or shopify hydrogen preview --build

  2. sebastian-meckovski commented on Mar 24, 2025

    @sebastian-meckovski
    Author

    @blittle npm run preview output:

    C:\Users\SebastianMeckovski\repos\shopfiy-shapediver-poc>npm run preview
    
    > [email protected] preview
    > shopify hydrogen preview --build
    
    vite v5.4.14 building for production...
    ✓ 1434 modules transformed.
    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.85 kB │ gzip:   1.64 kB
    dist/client/assets/reset-BKioPaen.css                                1.23 kB │ gzip:   0.55 kB
    dist/client/assets/app-CFDV3s0Q.css                                  5.60 kB │ gzip:   1.60 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-CTcRp9tg.js                       0.34 kB │ gzip:   0.24 kB
    dist/client/assets/pages._handle-DRZr6BeZ.js                         0.36 kB │ gzip:   0.28 kB
    dist/client/assets/cart-HPIPhX88.js                                  0.46 kB │ gzip:   0.32 kB
    dist/client/assets/policies._handle-Dkv9gksx.js                      0.47 kB │ gzip:   0.32 kB
    dist/client/assets/variants-CZH_ISnP.js                              0.49 kB │ gzip:   0.33 kB
    dist/client/assets/PaginatedResourceSection-DOmJbgwE.js              0.52 kB │ gzip:   0.32 kB
    dist/client/assets/blogs._index-DKRomhWH.js                          0.55 kB │ gzip:   0.35 kB
    dist/client/assets/blogs._blogHandle._articleHandle-B6QL2fUg.js      0.66 kB │ gzip:   0.44 kB
    dist/client/assets/collections._index--xhOmXq8.js                    0.81 kB │ gzip:   0.47 kB
    dist/client/assets/account-DPiX-jqj.js                               0.98 kB │ gzip:   0.51 kB
    dist/client/assets/collections.all-sQ_RCOlW.js                       1.00 kB │ gzip:   0.57 kB
    dist/client/assets/blogs._blogHandle._index-B5P-O-uq.js              1.10 kB │ gzip:   0.61 kB
    dist/client/assets/account.profile-CCYgKHC-.js                       1.15 kB │ gzip:   0.54 kB
    dist/client/assets/collections._handle-ZQJ33Svm.js                   1.22 kB │ gzip:   0.64 kB
    dist/client/assets/account.orders._index-BKR3VW6_.js                 1.29 kB │ gzip:   0.64 kB
    dist/client/assets/ProductPrice-B4hrIu0o.js                          1.29 kB │ gzip:   0.68 kB
    dist/client/assets/_index-bIwXqEV5.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-BRxBL1Y7.js                    2.88 kB │ gzip:   0.91 kB
    dist/client/assets/Money-C7LqNRT2.js                                 2.96 kB │ gzip:   1.27 kB
    dist/client/assets/search-CWDVq1r0.js                                3.65 kB │ gzip:   1.35 kB
    dist/client/assets/entry.client-Cd7zg0Uf.js                          3.80 kB │ gzip:   1.45 kB
    dist/client/assets/Image-CZDsFuI6.js                                 4.11 kB │ gzip:   1.66 kB
    dist/client/assets/account.addresses-E_J4PmVV.js                     4.68 kB │ gzip:   1.34 kB
    dist/client/assets/CartMain-eYxD9kc9.js                              5.50 kB │ gzip:   1.95 kB
    dist/client/assets/products._handle-BsbQP7G-.js                      8.84 kB │ gzip:   3.63 kB
    dist/client/assets/root-CnKu5wMF.js                                 13.12 kB │ gzip:   4.42 kB
    dist/client/assets/index-BauOezKG.js                                33.21 kB │ gzip:  11.64 kB
    dist/client/assets/components-CvKPrF23.js                          257.56 kB │ gzip:  82.90 kB
    dist/client/assets/index-xVRksQcc.js                             1,884.91 kB │ gzip: 428.99 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 13.42s
    
    vite v5.4.14 building SSR bundle for production...
    ✓ 1421 modules transformed.
    dist/server/oxygen.json                      0.06 kB
    dist/server/assets/favicon-DZkC1E9c.svg      0.69 kB
    dist/server/.vite/manifest.json              0.87 kB
    dist/server/assets/reset-BKioPaen.css        1.23 kB
    dist/server/assets/app-CFDV3s0Q.css          5.60 kB
    dist/server/index.js                     2,400.04 kB │ map: 11,887.23 kB
    ✓ built in 18.55s
    
    Environment variables injected into MiniOxygen:
    
    PUBLIC_STOREFRONT_ID                    from Oxygen
    PUBLIC_STOREFRONT_API_TOKEN             from Oxygen
    PUBLIC_STORE_DOMAIN                     from Oxygen
    PRIVATE_STOREFRONT_API_TOKEN            from Oxygen
    PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID   from Oxygen
    PUBLIC_CUSTOMER_ACCOUNT_API_URL         from Oxygen
    SHOP_ID                                 from Oxygen
    SESSION_SECRET                          from Oxygen
    ╭─ error ──────────────────────────────────────────────────────────────────────────────────────────╮
    │                                                                                                  │
    │  The Workers runtime failed to start. There is likely additional logging output above.           │
    │                                                                                                  │
    │  To investigate the issue, examine this stack trace:                                             │
    │    at #assembleAndUpdateConfig (miniflare/src/index.ts:1437)                                     │
    │    at processTicksAndRejections (node:internal/process/task_queues:105)                          │
    │    at runWith (miniflare/src/workers/shared/sync.ts:66)                                          │
    │    at #waitForReady (miniflare/src/index.ts:1519)                                                │
    │    at startWorkerdServer (Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/node_modules/@s  │
    │    hopify/cli/dist/workerd-PWW3BB6B.js:143)                                                      │
    │    at runPreview (Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/node_modules/@shopify/c  │
    │    li/dist/index.js:175198)                                                                      │
    │    at run (Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/node_modules/@shopify/cli/dist  │
    │    /index.js:175136)                                                                             │
    │    at _run (Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/node_modules/@shopify/cli/dis  │
    │    t/chunk-VSKRQ3JT.js:175008)                                                                   │
    │    at runCommand (Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/node_modules/@shopify/c  │
    │    li/dist/chunk-VSKRQ3JT.js:173833)                                                             │
    │    at run (Users/SebastianMeckovski/repos/shopfiy-shapediver-poc/node_modules/@shopify/cli/dist  │
    │    /chunk-VSKRQ3JT.js:175084)                                                                    │
    │                                                                                                  │
    ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
    

    shopify hydrogen preview --build output:

    'shopify' is not recognized as an internal or external command,
    operable program or batch file.
    

    I don't have it installed locally, but I can install it if it helps/

    You should be able to reproduce it if you implement that createSession code as in this branch in products.$handle.tsx. It needs to be inside UseEffect and fired on the client side. This needs to run on localhost:3000 because the backend service checks for origin header. Or you can try forking the repo.

    Let me know if you need more inforamtion.

  3. sebastian-meckovski commented on Mar 24, 2025

    @sebastian-meckovski
    Author

    @blittle The way you will know that the code has worked is that if you navigate to product page, the session will be created successfully it will log in console on the browser web tools

    Image

  4. blittle commented on Mar 24, 2025

    @blittle
    Contributor

    npm run preview runs the shopify hydrogen preview command for you. The preview command builds a hyrogen project in prod mode and runs it as a worker locally. And we are seeing the same error:

    service core:user:hydrogen: 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.

    I'm pretty sure this means that the built prod version of shapediver is a bit different than the dev version. Oxygen runs on a Cloudflare worker, and Cloudflare workers do not allow async code to be executed statically outside a function. I think you might need to open issue with them to figure out how/where that might be happening.

  5. sebastian-meckovski commented on Apr 8, 2025

    @sebastian-meckovski
    Author

    Is there a way to "force" these packages to only be included in the client side? These shapediver packages are meant to be used only on the client side only, they shouldn't run on Cloudflare workers

  6. sebastian-meckovski commented on Apr 10, 2025

    @sebastian-meckovski
    Author
  7. sebastian-meckovski commented on Apr 12, 2025

    @sebastian-meckovski
    Author

    I managed to make it work and deploy it by using dynamic imports. I believe this way it prevents it from compiling on the server side.

    useEffect(() => {
        const init = async () => {
          try {
            if (sessionRef.current) return;
            const {createSession} = await import('@shapediver/viewer.session');
    
            const session = await createSession({
              ticket: 'ticketId',
              modelViewUrl: 'modelViewUrl',
            });
            sessionRef.current = session;
            console.log('Session created:', session);
          } catch (error) {
            console.error('Error initializing the session or viewport:', error);
          }
        };
        init();
      }, []);

    And also had to add shapediver dependencies as external in vite.config.ts

    ...
      ssr: {
        external: ['@shapediver/viewer.session'],
        optimizeDeps: {
        include: [],
        },
      },
    ...

    This fixes the deployment process.

    However this no longer works n Hydrogen 2025.3.1 and Remix 2.16.1, errors locally. I created a separate issue for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions