Resolve AEM Cloud Manager deployment failures during Custom UI Test due to ESM/CommonJS compatibility
This article provides steps to resolve deployment pipeline failures during the Custom UI Test step in Adobe Experience Manager (AEM) Cloud Manager, which are caused by compatibility issues between ES modules (ESM) and CommonJS dependencies.
Description description
Environment
Adobe Experience Manager as a Cloud Service (all versions)
Issue/Symptoms
- The deployment pipeline fails during the Custom UI Test step in Cloud Manager.
- Error logs show messages such as: ERR_REQUIRE_ESM: Must use import to load ES Module: @wdio/logger.
- Additional errors occur when ESM-only reporters (for example,
wdio-html-nice-reporter) are loaded usingrequire()in configuration files, resulting in similar ERR_REQUIRE_ESM errors. - Indexing failures may also occur if the target environment is not fully active during deployment.
Cause
The failures are due to incompatibilities between CommonJS and ES module dependencies in the custom UI test configuration. Additionally, deployment may fail if the target environment is not active.
Resolution resolution
Follow the steps below to resolve the issue:
-
Review your custom UI test dependencies, especially those related to WebdriverIO (such as
@wdio/loggerandwdio-html-nice-reporter). -
Update import statements for ESM compatibility:
- Remove all
require('@wdio/logger')imports from CommonJS files (such aslauncher.jsandcomparisonstrategy.js). - Replace these imports with simple logging statements or use dynamic
import()if necessary.
- Remove all
-
Adjust reporter configuration:
- If using ESM-only reporters (such as
wdio-html-nice-reporter), ensure they are loaded usingimportsyntax rather thanrequire()in configuration files (such aswdio.conf.commons.js). - Refactor configuration files to be ESM-compatible if required by your dependency set, or remove ESM-only reporters from the reporters array for the Cloud Manager run.
- If using ESM-only reporters (such as
-
Ensure the target environment is fully active before running the deployment pipeline to avoid indexing failures. If the environment was previously hibernated, activate it and re-run the pipeline.
-
Re-run the deployment pipeline and monitor for errors.
-
Verify that the Custom UI Test step completes successfully and that the deployment proceeds without module compatibility errors.