Skip to content

Commit 293bbdd

Browse files
committed
fix(nodejs): window is not defined in node env
1 parent 13f57f5 commit 293bbdd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ export type Namespace = {
1515
};
1616

1717
const initializeGlobalNamespace = () => {
18-
let holder = window;
18+
let holder:any;
1919

2020
// if there is no window obj use nodejs global lib variable
21-
if (typeof holder !== 'object') {
21+
if (window && typeof window !== 'object') {
2222
holder = globalHolder;
23+
} else {
24+
holder = window
2325
}
2426

2527
// @ts-ignore
@@ -82,7 +84,7 @@ export const loadModules = (modulesList) => Promise.all(modulesList.map(({ id, u
8284
* @param {*} url
8385
*/
8486
export const loadModule = (id: string, url: string) => {
85-
if (typeof window !== 'object') {
87+
if (window && typeof window !== 'object') {
8688
return Promise.reject(new Error('Load module is working only on browser env'));
8789
}
8890

@@ -152,7 +154,7 @@ export const loadModule = (id: string, url: string) => {
152154
*/
153155
export const registerModule = (id: string, instance: any, metadata?: any) => {
154156
// loader not working on nodejs envs
155-
if (typeof window !== 'object') {
157+
if (window && typeof window !== 'object') {
156158
return;
157159
}
158160

0 commit comments

Comments
 (0)