webdriverio-community / wdio-video-reporter

Reporter for WebdriverIO that makes videos of failed tests and has optional allure integration

Home Page:https://webdriver.io/docs/wdio-video-reporter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CJS build is broken

Jmelwood opened this issue · comments

Describe the bug
After the changes made in v4/4.0.1, it doesn't look like the CJS version of the file works any longer.
First problem I noticed is that it does not point properly to the CJS file when run through ts-node with a tsconfig set as node resolution.
I know how to fix that problem with an edit to wdio-video-reporter's package.json, but ran into a second issue that I'm unsure why it's happening now, which is once the correct file is read, it expects all the imports inside the CJS file to also have a CJS version. This is not the case for @wdio/reporter (only ESM export), so it fails to start.

Log
First problem:

2023-04-12T22:57:51.689Z ERROR @wdio/config:ConfigParser: Failed loading configuration file: file:///Users/jelwood/Documents/debug-wdio/wdio.conf.js: require() of ES Module /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.mjs not supported.
Instead change the require of /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.mjs to a dynamic import() which is available in all CommonJS modules.
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.mjs not supported.
Instead change the require of /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/jelwood/Documents/debug-wdio/wdio.conf.js:1:15) {
  code: 'ERR_REQUIRE_ESM'
}

Second problem:

2023-04-12T22:59:13.162Z ERROR @wdio/config:ConfigParser: Failed loading configuration file: file:///Users/jelwood/Documents/debug-wdio/wdio.conf.js: require() of ES Module /Users/jelwood/Documents/debug-wdio/node_modules/@wdio/reporter/build/index.js from /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.cjs not supported.
Instead change the require of index.js in /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.cjs to a dynamic import() which is available in all CommonJS modules.
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/jelwood/Documents/debug-wdio/node_modules/@wdio/reporter/build/index.js from /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.cjs not supported.
Instead change the require of index.js in /Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/jelwood/Documents/debug-wdio/node_modules/wdio-video-reporter/dist/wdio-video-reporter.cjs:5:36)
    at Object.<anonymous> (/Users/jelwood/Documents/debug-wdio/wdio.conf.js:1:15) {
  code: 'ERR_REQUIRE_ESM'
}

To Reproduce
See this gist: https://gist.github.com/Jmcosel/e9a850d31f72c662fbc8067da30c48fe

Expected behavior
CJS support is still present.

Environment (please complete the following information):

  • wdio-video-reporter version: 4.0.1
  • WebdriverIO version: 8.8.2
  • Mode: WDIO Testrunner
  • If WDIO Testrunner, running sync/async: async
  • Node.js version: 18.5.0
  • NPM version: 9.5.0
  • Browser name and version: Chrome 112
  • Platform name and version: macOS Ventura

Desktop (please complete the following information):

  • OS: macOS Ventura
  • Browser: chrome
  • Version: 112

Thanks for reporting!

Any contributions that resolves the bug are highly appreciated. Don't expect this to be picked up by active contributors as they have their own priorities. If you depend on this bug to be fixed, your contribution is required. Please take a look into our contribution guidelines and let us know if you have any questions. Cheers!

@mbIkola might have ideas since he just made a change a couple days ago regarding this?

@mbIkola might have ideas since he just made a change a couple days ago regarding this?

That's probably one of the reasons why it's required to do a major version bump.
wdio-video-reporter obviously depends on wdio-reporter. The last one is ESM-only, and does not export CJS

That story about cjs vs esm vs mixed and other stuff around "interopDefault" is a bit challenging for me; I would highly appreciate for any hint regarding how to import ESM external dependency into CJS module and what rollup config I should use for this.

Problem 1 about invalid exports in package.json is (probably) fixed at #101, please take a look

Any workaround for this?

I am not sure which changes have been introduced recently but any contributions are appreciated.

I am not sure which changes have been introduced recently but any contributions are appreciated.

I did some tests, and I'm starting to think v4 will work only with wdio 8. Will run the test soon

I fixed the CJS export so it should work not with ESM and CJS. I am certain that this reporter should still work with v7 however we recommend to update to v8.