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 ReferenceError: document is not defined #16277

Closed
7 tasks done
JS-mark opened this issue Mar 26, 2024 · 6 comments · Fixed by #16318
Closed
7 tasks done

Uncaught ReferenceError: document is not defined #16277

JS-mark opened this issue Mar 26, 2024 · 6 comments · Fixed by #16318
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release

Comments

@JS-mark
Copy link

JS-mark commented Mar 26, 2024

Describe the bug

image

使用了 wasm

Reproduction

https://baidu.com

Steps to reproduce

pnpm dev

System Info

System:
    OS: macOS 14.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.20 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
    pnpm: 8.15.1 - /opt/homebrew/bin/pnpm
    bun: 1.0.18 - ~/.bun/bin/bun
  Browsers:
    Chrome: 123.0.6312.59
    Safari: 17.4
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.1.0 => 1.1.0
    @vitejs/plugin-vue: ^5.0.4 => 5.0.4
    vite: ^5.2.6 => 5.2.6

Used Package Manager

pnpm

Logs

No response

Validations

Copy link

Hello @JS-mark. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@felladrin
Copy link

Also getting this error when running Vite in dev mode.
I am not sure yet what causes this, but it started happening on Vite v5.2.
A workaround is to downgrade it to v5.1. (npm install vite@~5.1)

@logicsb
Copy link

logicsb commented Mar 29, 2024

I have this error using ffmpeg.wasm. I've back to 5.1.7 and works fine. This error occur exactly when try to create an instance of the ffmpeg.

@JS-mark
Copy link
Author

JS-mark commented Mar 29, 2024

I have this error using ffmpeg.wasm. I've back to 5.1.7 and works fine. This error occur exactly when try to create an instance of the ffmpeg.

Yeah, I got back to normal when I was demoted to 5.1.7.

@felladrin
Copy link

felladrin commented Mar 29, 2024

Found the cause and created the minimal reproduction on StackBlitz:
https://stackblitz.com/edit/vitejs-vite-ghbtzp?file=vite.config.ts

Important:
Due to StackBlitz limitations, to see the results I mention below, you need to open the preview in a new tab:
image
Or download the files and run the demo locally.


When using Vite 5.2, the error starts happening when we add cross-origin isolation to the dev server:

    {
      name: 'configure-response-headers',
      configureServer: (server) => {
        server.middlewares.use((_, res, next) => {
          res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
          res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
          next();
        });
      },
    },
image

Note how the app starts working again when the headers are removed:

    {
      name: 'configure-response-headers',
      configureServer: (server) => {
        server.middlewares.use((_, res, next) => {
-         res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
-         res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
          next();
        });
      },
    },
image

cc @sapphi-red @ngxson

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release feat: web workers and removed needs reproduction labels Mar 30, 2024
@jlarmstrongiv
Copy link

Related to #15852 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants