diff --git a/.changeset/chilled-rats-provide.md b/.changeset/chilled-rats-provide.md new file mode 100644 index 00000000000..e394a6311e7 --- /dev/null +++ b/.changeset/chilled-rats-provide.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +Attempt dynamically importing hook as a module if package.json `type=module`, if fail, fallback to default `require` diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index adfadfa047c..c62a75f48c0 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -756,8 +756,12 @@ export function normalizeExt(ext: string) { async function resolveModule(type: string | undefined, name: string): Promise { const extension = path.extname(name).toLowerCase() const isModuleType = type === "module" - if (extension === ".mjs" || (extension === ".js" && isModuleType)) { - return await eval("import('" + name + "')") + try { + if (extension === ".mjs" || (extension === ".js" && isModuleType)) { + return await eval("import('" + name + "')") + } + } catch (error) { + log.debug({ moduleName: name }, "Unable to dynamically import hook, falling back to `require`") } return require(name) }