Skip to content

Commit 63a0044

Browse files
authored
fix: Attempt dynamically importing hook as a module if package.json type=module, if fail, fallback to default require (#8042)
1 parent 94677f3 commit 63a0044

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/chilled-rats-provide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
Attempt dynamically importing hook as a module if package.json `type=module`, if fail, fallback to default `require`

packages/app-builder-lib/src/platformPackager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,12 @@ export function normalizeExt(ext: string) {
756756
async function resolveModule<T>(type: string | undefined, name: string): Promise<T> {
757757
const extension = path.extname(name).toLowerCase()
758758
const isModuleType = type === "module"
759-
if (extension === ".mjs" || (extension === ".js" && isModuleType)) {
760-
return await eval("import('" + name + "')")
759+
try {
760+
if (extension === ".mjs" || (extension === ".js" && isModuleType)) {
761+
return await eval("import('" + name + "')")
762+
}
763+
} catch (error) {
764+
log.debug({ moduleName: name }, "Unable to dynamically import hook, falling back to `require`")
761765
}
762766
return require(name)
763767
}

0 commit comments

Comments
 (0)