Skip to content

Commit

Permalink
fix(nodejs): window is not defined in node env
Browse files Browse the repository at this point in the history
  • Loading branch information
pcholuj committed Mar 25, 2020
1 parent 13f57f5 commit 293bbdd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export type Namespace = {
};

const initializeGlobalNamespace = () => {
let holder = window;
let holder:any;

// if there is no window obj use nodejs global lib variable
if (typeof holder !== 'object') {
if (window && typeof window !== 'object') {
holder = globalHolder;
} else {
holder = window
}

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

Expand Down Expand Up @@ -152,7 +154,7 @@ export const loadModule = (id: string, url: string) => {
*/
export const registerModule = (id: string, instance: any, metadata?: any) => {
// loader not working on nodejs envs
if (typeof window !== 'object') {
if (window && typeof window !== 'object') {
return;
}

Expand Down

0 comments on commit 293bbdd

Please sign in to comment.