-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
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:
- fix: avoid using
import.meta.url
for relative assets if output is not ESM (fixes plugin-legacy Unexpected token import #9297) (fix: avoid usingimport.meta.url
for relative assets if output is not ESM (fixes #9297) #9381)
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.