Shopify / hydrogen

Hydrogen lets you build faster headless storefronts in less time, on Shopify.
https://hydrogen.shop
MIT License
1.45k stars 280 forks source link

Oxygen: Deployment failed, error: Uncaught ReferenceError: window is not defined #2647

Closed octave closed 1 week ago

octave commented 1 week ago

Which package or tool is having this issue?

Oxygen

What version of that package or tool are you using?

2.0.9

What version of Remix are you using?

2.13.1

Steps to Reproduce

When deploying my Hydrogen store @shopify/hydrogen@2024.10.0 to Oxygen via Github (standard setup) and from the command line as well shopify hydrogen deploy. It currently fails right at the end of the deployment:

Deploying to Oxygen..
Deployment failed, error: Uncaught ReferenceError: window is not defined
  at worker.mjs:5080:5433
  at worker.mjs:5080:17531
╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Uncaught ReferenceError: window is not defined                              │
│    at worker.mjs:5080:5433                                                   │
│    at worker.mjs:5080:17531                                                  │
│                                                                              │
│                                                                              │
│  Retrying the deployment may succeed.                                        │
│                                                                              │
│  Next steps                                                                  │
│    • If the issue persists, please check the Shopify status page [1] for     │
│      any known issues.                                                       │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
[1] https://status.shopify.com/

My Github workflow file is up-to-date too:

name: Storefront 0000000000
on: [push]

permissions:
  contents: read
  deployments: write

jobs:
  deploy:
    name: Deploy to Oxygen
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup node.js
        uses: actions/setup-node@v4
        with:
          node-version: 'lts/*'
          check-latest: true

      - name: Cache node modules
        id: cache-npm
        uses: actions/cache@v4
        env:
          cache-name: cache-node-modules
        with:
          path: ~/.npm
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install dependencies
        run: npm ci

      - name: Build and Publish to Oxygen
        run: npx shopify hydrogen deploy
        env:
          SHOPIFY_HYDROGEN_DEPLOYMENT_TOKEN: ${{ secrets.OXYGEN_DEPLOYMENT_TOKEN_0000000000 }}

Is there a way to have more details/logs on where to look/investigate?

octave commented 1 week ago

I found the issue, it happens when using @segment/analytics-next@1.76.0:

import {AnalyticsBrowser} from '@segment/analytics-next';

I reported it here: https://github.com/segmentio/analytics-next/issues/1194