Skip to content

Commit 91a92b1

Browse files
Varixowmertens
authored andcommitted
fix: ssg build windows error
1 parent 1b275e1 commit 91a92b1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

packages/qwik-router/src/ssg/node/node-main.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
import fs from 'node:fs';
1111
import { cpus as nodeCpus } from 'node:os';
1212
import { Worker } from 'node:worker_threads';
13-
import { isAbsolute, resolve } from 'node:path';
13+
import { dirname, extname, isAbsolute, join, resolve } from 'node:path';
1414
import { ensureDir } from './node-system';
1515
import { normalizePath } from '../../utils/fs';
1616
import { createSingleThreadWorker } from '../worker-thread';
@@ -78,14 +78,23 @@ export async function createNodeMainProcess(sys: System, opts: SsgOptions) {
7878

7979
let workerFilePath: string | URL;
8080

81+
// Launch the worker using the package's index module, which bootstraps the worker thread.
8182
if (typeof __filename === 'string') {
82-
workerFilePath = __filename;
83+
// CommonJS path
84+
const ext = extname(__filename) || '.js';
85+
workerFilePath = join(dirname(__filename), `index${ext}`);
8386
} else {
84-
workerFilePath = import.meta.url;
85-
}
87+
// ESM path (import.meta.url)
88+
const thisUrl = new URL(import.meta.url);
89+
const pathname = thisUrl.pathname || '';
90+
let ext = '.js';
91+
if (pathname.endsWith('.ts')) {
92+
ext = '.ts';
93+
} else if (pathname.endsWith('.mjs')) {
94+
ext = '.mjs';
95+
}
8696

87-
if (typeof workerFilePath === 'string' && workerFilePath.startsWith('file://')) {
88-
workerFilePath = new URL(workerFilePath);
97+
workerFilePath = new URL(`./index${ext}`, thisUrl);
8998
}
9099

91100
const nodeWorker = new Worker(workerFilePath, { workerData: opts });
@@ -146,7 +155,7 @@ export async function createNodeMainProcess(sys: System, opts: SsgOptions) {
146155
});
147156

148157
nodeWorker.on('exit', (code) => {
149-
if (code !== 1) {
158+
if (code !== 0) {
150159
console.error(`worker exit ${code}`);
151160
}
152161
});

0 commit comments

Comments
 (0)