Skip to content

Commit

Permalink
fix: somehow globalThis.require is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 9, 2023
1 parent b8893a3 commit 968714f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function guessFormat(inputFile: string): "esm" | "cjs" {
return "cjs"
}

// Injected by TSUP
declare const TSUP_FORMAT: "esm" | "cjs"

declare const jest: any

// Stolen from https://github.com/vitejs/vite/blob/0713446fa4df678422c84bd141b189a930c100e7/packages/vite/src/node/utils.ts#L606
Expand All @@ -47,9 +50,9 @@ export const dynamicImport: RequireFunction = async (
const fn =
format === "esm"
? (file: string) => import(file)
: typeof globalThis.require === "function"
? globalThis.require
: createRequire(import.meta.url)
: TSUP_FORMAT === "esm"
? createRequire(import.meta.url)
: require
return fn(id)
}

Expand Down

0 comments on commit 968714f

Please sign in to comment.