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

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

Closed
HalfdanJ opened this issue Oct 8, 2024 · 3 comments · Fixed by #12779
Closed

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

HalfdanJ opened this issue Oct 8, 2024 · 3 comments · Fixed by #12779

Comments

@HalfdanJ
Copy link

HalfdanJ commented Oct 8, 2024

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

@HalfdanJ
Copy link
Author

HalfdanJ commented Oct 8, 2024

After further looking into this, it seems like this might be a cache / cdn issue. The file public.Dvbes-1E.js is served with the wrong key 1n0gls, but when i look at the docker artifact that has been deployed, the files contains the right key 1lw3djs. Is it possible the change in #12700 resulted in the key changing, but the filename staying the same, and therefore resulting in the file having changed content without changing filename?

@HalfdanJ
Copy link
Author

HalfdanJ commented Oct 8, 2024

I have isolated the issue and updated the issue to contain reproduction steps. Issue is that the key changes when package.json changes, but the filename doesnt change so it has become mutable.

dummdidumm added a commit that referenced this issue Oct 9, 2024
This reverts commit 3591411.

#12700 did introduce a bug where the file name stays the same, but the contents of a file can change because of a changed version. Revert for now and take another look at tackling this later.

Fixes #12771
Reopens #12260
@sickl8
Copy link

sickl8 commented Oct 13, 2024

Encountered the same problem recently, fixed by enabling "Disable Cache" in browser dev tools for each CI build of a commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants