Skip to content

Commit

Permalink
ESM require => import handle fix (#4811)
Browse files Browse the repository at this point in the history
* ESM require handle fix
  • Loading branch information
gilgardosh authored Nov 15, 2022
1 parent 65c2a85 commit cf9c6d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tame-nails-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/utils': patch
---

ESM require > import handling fix
2 changes: 1 addition & 1 deletion packages/utils/src/defaultImportFn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export async function defaultImportFn(path: string) {
let module = await import(/* @vite-ignore */ path).catch(e => {
if (e.message.includes('Must use import to load ES Module')) {
if (e.code === 'ERR_REQUIRE_ESM') {
// eslint-disable-next-line no-new-func
return new Function(`return import(${JSON.stringify(path)})`)();
}
Expand Down

0 comments on commit cf9c6d5

Please sign in to comment.