Skip to content

Commit ef749ed

Browse files
authored
fix(worker): dont throw on import.meta.url in ssr (#8846)
1 parent 1a498f7 commit ef749ed

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

packages/vite/src/node/plugins/workerImportMetaUrl.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
7676
name: 'vite:worker-import-meta-url',
7777

7878
async transform(code, id, options) {
79-
const query = parseRequest(id)
80-
let s: MagicString | undefined
8179
if (
80+
!options?.ssr &&
8281
(code.includes('new Worker') || code.includes('new SharedWorker')) &&
8382
code.includes('new URL') &&
8483
code.includes(`import.meta.url`)
8584
) {
85+
const query = parseRequest(id)
86+
let s: MagicString | undefined
8687
const cleanString = stripLiteral(code)
8788
const workerImportMetaUrlRE =
8889
/\bnew\s+(Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/g
@@ -96,13 +97,6 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
9697
const urlEnd = urlStart + emptyUrl.length
9798
const rawUrl = code.slice(urlStart, urlEnd)
9899

99-
if (options?.ssr) {
100-
this.error(
101-
`\`new URL(url, import.meta.url)\` is not supported in SSR.`,
102-
urlIndex
103-
)
104-
}
105-
106100
// potential dynamic template string
107101
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
108102
this.error(

0 commit comments

Comments
 (0)