Skip to content

Uncaught error on startup: Cannot read env of undefined #12771

Closed
@HalfdanJ

Description

@HalfdanJ

Describe the bug

After updating sveltekit from 2.6.2 to 2.6.3, the build version of the app is broken on startup with the following error

public.Dvbes-1E.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'env')
    at public.Dvbes-1E.js:1:376

The code that is running is

const d = globalThis.__sveltekit_1n0gls.env;

I can see that globalThis.__sveltekit_1n0gls doesn't exist, but globalThis.__sveltekit_aqr0w does. So it seems like somehow the keys gets mixed up in the build. I suspect introduced in #12700

Reproduction

  1. Create a new sveltekit project, and make a build
  2. Take note of the variable name globalThis.__sveltekit_* in client/_app/immutable/chunks/entry.*.js
  3. Make a change to package.json, for example add a new dependency
  4. Make new build, notice that the entry.*.js file has not changed filename (same key), but that globalThis.__sveltekit_* has changed key, so the file has become mutable

The build is still valid by itself, but if application is served behind a cdn, the old file will be served since filename doesnt change.

Logs

No response

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 2.38 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
    pnpm: 9.1.1 - ~/.nvm/versions/node/v20.15.1/bin/pnpm
    bun: 1.1.5 - ~/.bun/bin/bun
  Browsers:
    Chrome: 129.0.6668.90
    Safari: 17.6
  npmPackages:
    @sveltejs/adapter-node: 5.2.5 => 5.2.5 
    @sveltejs/enhanced-img: 0.3.8 => 0.3.8 
    @sveltejs/kit: 2.6.3 => 2.6.3 
    svelte: 4.2.19 => 4.2.19 
    vite: 5.4.8 => 5.4.8

Severity

blocking an upgrade

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions