webdriverio: [🐛 Bug]: CJS require of @wdio/cli and @wdio/reporter not implemented
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
8.4
Node.js Version
16.13.2
Mode
WDIO Testrunner
Which capabilities are you using?
No response
What happened?
Tests are written in a cjs project with the testrunner started programmatically. When upgrading to v8 some wdio modules are no longer possible to require.
const Launcher = require('@wdio/cli').default
const WDIOReporter = require('@wdio/reporter').default;
fails since they only support esm import.
A temporary workaround is to use const { Launcher } = await import('@wdio/cli');
but in the case of @wdio/reporter that is a bit trickier.
What is your expected behavior?
To be able to use
const Launcher = require('@wdio/cli').default
const WDIOReporter = require('@wdio/reporter').default;
How to reproduce the bug.
Use
require('@wdio/cli').default
or
require('@wdio/reporter').default
in v8
Relevant log output
Launcher failed to start the test Error [ERR_REQUIRE_ESM]: require() of ES Module
Code of Conduct
- I agree to follow this project’s Code of Conduct
Is there an existing issue for this?
- I have searched the existing issues
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 28 (19 by maintainers)
Keeping this open as we still should provide a CJS artifact for
@wdio/reporterIn 7.x I was able to write my config file in TS and import my custom reporter written in TS all using the same options as my tests written in TS thanks ts-node and smart engineering. Now this ‘internal’ decision breaks two of those at a time. I see authors using sneaky tricks like importing .js files in TS to avoid proper imports. advocating top-level awaits or changing entire project module types in package.js to get things going again. This is a community friction issue that isn’t going to go away. 8.0 has been out for a year and you’re getting lots of issues.
Hi @ashil88 ,
I found a bug that I’m working on fixing, but I doubt that it’s the error you are getting. Do you have a sample project where I can see the error?
You could also try:
const {Launcher} = require('@wdio/cli');Don’t believe that @wdio/cli has a default export and it only exposes named exports.
I recommend have the service create artifacts for ESM and CJS so it can be potentially used for v7 CJS users as well as v8 ESM ones. Have a close look how some of our other service do this. You basically write your service in ESM and have a CJS file that imports the ESM package and just re-exports it.