Skip to content

Commit a764cf4

Browse files
committed
fix(core): throw when importing twice
this should make it easier to detect build misconfigurations
1 parent d23e066 commit a764cf4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/qwik-router/src/ssg/worker-thread.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import type {
1414
} from './types';
1515

1616
export async function workerThread(sys: System) {
17+
// Special case: we allow importing qwik again in the same process, it's ok because we just needed the serializer
18+
// TODO: remove this once we have vite environment API and no longer need the serializer separately
19+
delete (globalThis as any).__qwik;
1720
const ssgOpts = sys.getOptions();
1821
const pendingPromises = new Set<Promise<any>>();
1922

@@ -42,6 +45,9 @@ export async function workerThread(sys: System) {
4245
}
4346

4447
export async function createSingleThreadWorker(sys: System) {
48+
// Special case: we allow importing qwik again in the same process, it's ok because we just needed the serializer
49+
// TODO: remove this once we have vite environment API and no longer need the serializer separately
50+
delete (globalThis as any).__qwik;
4551
const ssgOpts = sys.getOptions();
4652
const pendingPromises = new Set<Promise<any>>();
4753

packages/qwik/src/core/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
// Protect against duplicate imports
3+
//////////////////////////////////////////////////////////////////////////////////////////
4+
import { version } from './version';
5+
if ((globalThis as any).__qwik) {
6+
throw new Error(
7+
`Qwik version ${(globalThis as any).__qwik} already imported while importing ${version}. Verify external vs bundled imports etc.`
8+
);
9+
}
10+
(globalThis as any).__qwik = version;
11+
112
//////////////////////////////////////////////////////////////////////////////////////////
213
// Developer Core API
314
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)