webdriverio-community/wdio-cucumberjs-json-reporter

Provide CJS export for this reporter

a-skindzer opened this issue ยท 10 comments

Environment:

  • Node.js version: v18.16.0
  • NPM version: 9.6.4
  • webdriver.io version: 8.9.0
  • @wdio/cucumber-framework version: 8.8.7
  • wdio-cucumberjs-json-reporter version: 5.0.0

Config of webdriver.io and the reporter

export const config: Options.Testrunner = {
    // ...
    reporters: ['spec', 'cucumberjs-json'],
    // ...
}

Describe the bug
I get the following error when I try to use wdio-cucumberjs-json-reporter v5.0.0 with webdriverio v8.9.0. The error says wdio-cucumberjs-json-reporter package is not installed but it's installed:

[0-0] 2023-05-02T08:58:28.058Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2023-05-02T08:58:28.151Z ERROR @wdio/local-runner: Failed launching test session: Error: Couldn't find plugin "cucumberjs-json" reporter, neither as wdio scoped package "@wdio/cucumberjs-json-reporter" nor as community package "wdio-cucumberjs-json-reporter". Please make sure you have it installed!
[0-0]     at initialisePlugin (file:///home/skindzer/WebstormProjects/reporter/node_modules/@wdio/utils/build/initialisePlugin.js:36:11)
[0-0]     at async BaseReporter._loadReporter (file:///home/skindzer/WebstormProjects/reporter/node_modules/@wdio/runner/build/reporter.js:178:30)
[0-0]     at async Promise.all (index 1)
[0-0]     at async BaseReporter.initReporters (file:///home/skindzer/WebstormProjects/reporter/node_modules/@wdio/runner/build/reporter.js:23:27)
[0-0]     at async Runner.run (file:///home/skindzer/WebstormProjects/reporter/node_modules/@wdio/runner/build/index.js:68:9)
[0-0] FAILED

To Reproduce
I've prepare a project where this error is reproducible: https://github.com/a-skindzer/reporter_issue_example

import cucumberJson from 'wdio-cucumberjs-json-reporter'; statement also doesn't work and give 'Module Not Found' error.

import cucumberJson from 'wdio-cucumberjs-json-reporter'; statement also doesn't work and give 'Module Not Found' error.

with the new version 5.0.1 we are not seeing the above error but getting a new error

ERROR @wdio/config:ConfigParser: Failed loading configuration file: file:///C:/***wdio.conf.js: Cannot use import statement outside a module
C:*
\node_modules\wdio-cucumberjs-json-reporter\dist\index.js:1
import path from 'node:path';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at ModuleWrap. (node:internal/modules/esm/translators:170:29)
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)

with the new version 5.0.1 we are not seeing the above error but getting a new error

Which WebdriverIO version are you using?

with the new version 5.0.1 we are not seeing the above error but getting a new error

Which WebdriverIO version are you using?

it is 8.8.6

You are using CJS and there is not CJS export for it yet. Feel free to contribute it.

You are using CJS and there is not CJS export for it yet. Feel free to contribute it.

I am using ESM .. but still getting this..

Also, I cannot see "type": "module" in the package.json for the reporter https://github.com/webdriverio-community/wdio-cucumberjs-json-reporter/blob/main/package.json

is that not expected? I did try adding it in my local and run but got this

ERROR @wdio/config:ConfigParser: Failed loading configuration file: file:///C:/****-wdio.conf.js: Named export 'existsSync' not found. The requested module 'fs-extra' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'fs-extra';
const { existsSync, outputJsonSync, readJsonSync } = pkg;

file:///C:/****/node_modules/wdio-cucumberjs-json-reporter/dist/index.js:2
import { existsSync, outputJsonSync, readJsonSync } from 'fs-extra';
^^^^^^^^^^
SyntaxError: Named export 'existsSync' not found. The requested module 'fs-extra' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'fs-extra';
const { existsSync, outputJsonSync, readJsonSync } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async ConfigParser.addConfigFile (file:///C:/***/node_modules/@wdio/config/build/lib/ConfigParser.js:85:36)
at async ConfigParser.initialize (file:///C:/****/node_modules/@wdio/config/build/lib/ConfigParser.js:47:13)
at async Launcher.run (file:///C:/****/node_modules/@wdio/cli/build/launcher.js:37:9)
at async Module.run (file:///C:/****/node_modules/@wdio/cli/build/run.js:64:20)

SyntaxError: Named export 'existsSync' not found. The requested module 'fs-extra' is a CommonJS module, which may not support all module.exports as named exports.

This is the problem.

Is it something within this package or the setup I have

I just pushed a fix in v5.0.2. Please try and report back if the problem was resolved. @a-skindzer please update to the latest version.

@christian-bromann thank you!
looks like everything works as expected