Skip to content

wdio-ui5-service@3.0.10 cannot be loaded via require() in a CommonJS project. #778

Description

@mccmrunal

Describe the bug

wdio-ui5-service@3.0.10 cannot be loaded via require() in a CommonJS project. The package's root package.json declares "type": "module", but the CommonJS build shipped in dist/cjs/ has no dist/cjs/package.json marker. Node therefore parses the CommonJS output (dist/cjs/index.js) as an ES module and throws on first load:

ReferenceError: exports is not defined in ES module scope

Because both main and the require export condition point at dist/cjs/index.js, any CommonJS consumer — including a standard wdio.conf.js that does const { default } = require("wdio-ui5-service") — crashes at load time, before any test runs.

To Reproduce

Minimal, isolated reproduction (no UI5 app or wdio config required):

  1. mkdir wdi5-repro && cd wdi5-repro
  2. npm init -y
  3. npm install wdio-ui5-service@3.0.10
  4. node -e "require('wdio-ui5-service')"
  5. See error

Expected behavior

require("wdio-ui5-service") resolves and returns the service export (as it does once a dist/cjs/package.json containing {"type":"commonjs"} is present). ESM import already works — only the CommonJS entry is broken.

Logs/Console Output

$> node -e "require('wdio-ui5-service')"
.../node_modules/wdio-ui5-service/dist/cjs/index.js:19
Object.defineProperty(exports, "__esModule", { value: true });
                      ^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension
and '.../node_modules/wdio-ui5-service/package.json' contains "type": "module".
To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at .../node_modules/wdio-ui5-service/dist/cjs/index.js:19:23
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:541:37)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:366:47)

Screenshots

n/a — crashes at module load, before a browser starts.

Runtime Env (please complete the following information):

  • wdi5/wdio-ui5-service-version: 3.0.10
  • UI5 version: n/a — fails before any UI5 is loaded (occurs on a bare npm install, no app)
  • wdio-version (output of wdio --version): 9.29.1
  • node-version (output of node --version): v24.15.0
  • OS: Windows 11 (also reproducible on any OS — packaging-only)
  • Browser + Version: n/a — fails before browser launch

Additional context

Root cause: the require export condition and main both resolve to dist/cjs/index.js, but with "type": "module" at the package root and no dist/cjs/package.json, Node treats that CommonJS output as ESM.

Suggested fix: emit dist/cjs/package.json = {"type":"commonjs"} (and, for symmetry, dist/esm/package.json = {"type":"module"}) as part of the build. Verified locally that adding a post-build step after the _build:cjs / _build:esm tsc runs makes require() succeed while keeping import working. Happy to open a PR.

Reproducible on both a bare install and in a real CommonJS wdio.conf.js project. Not browser- or --headless-dependent, and independent of the wdio version — the failure is purely at package load.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions