Skip to content

"document" is not defined for xxxx.wasm?url #9879

@nine-fox

Description

@nine-fox

Describe the bug

Hi there,

the following error is fired when I use latest version 3.0.9 to compile the following code in production mode:

import xxxx from "../../xxx.wasm?url";

The error is as follows.
"document" is not defined

So I switch back to old version 2.9.x and the error disappear

After some investigation, I found it is caused by the changeset:

The following code doesn't check document variable:

const getRelativeUrlFromDocument = (relativePath: string, umd = false) =>
getResolveUrl(
'${relativePath}', ${ umd ? typeof document === 'undefined' ? location.href : : '' }document.currentScript && document.currentScript.src || document.baseURI
)

So I suggest to add a simple "typeof document !== 'undefined'" in the last sentence.

Reproduction

https://stackblitz.com/edit/vitejs-vite-85cthg?file=vite.config.js

run "npm run build" then "vite preview"

System Info

"document" is not defined

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: web workersp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions