Cucumber-js: Changes in 7.2.0 break external reporters

Created on 21 Apr 2021  路  4Comments  路  Source: cucumber/cucumber-js

Hey @davidjgoss and @charlierudolph!

It looks like support for ESM introduced in 7.2.0 (#1589) breaks a number of external reporters, as it no longer allows for sub-module imports.

This manifests itself with an error in projects that attempt a sub-module import.

For example, calling either:

const TestCaseHookDefinition = require('@cucumber/cucumber/lib/models/test_case_hook_definition')

or:

import TestCaseHookDefinition from '@cucumber/cucumber/lib/models/test_case_hook_definition';

results in:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/models/test_case_hook_definition' 
 is not defined by "exports" in /path/to/project/node_modules/@cucumber/cucumber/package.json

Affected projects I'm aware of (there could be more):

  • Serenity/JS - @serenity-js/cucumber module relies on following sub-module imports:

    • @cucumber/cucumber/package.js (to read the version)

    • @cucumber/cucumber/lib/models/test_case_hook_definition - to instantiate TestCaseHookDefinition

  • @jbpros cucumber-pretty-formatter - see jbpros/cucumber-pretty-formatter#2, which relies on loading:

    • @cucumber/cucumber/lib/formatter - IFormatterOptions

    • @cucumber/cucumber/lib/formatter/helpers - formatLocation

    • @cucumber/cucumber/lib/formatter/helpers/gherkin_document_parser - getGherkinExampleRuleMap, getGherkinScenarioMap, getGherkinStepMap

    • @cucumber/cucumber/lib/formatter/helpers/pickle_parser - getPickleStepMap

  • @christian-bromann - @wdio/cucumber-framework, which loads:

    • @cucumber/cucumber/lib/support_code_library_builder/types - ITestCaseHookParameter

    • @cucumber/cucumber/lib/formatter/helpers/event_data_collector - EventDataCollector

    • @cucumber/cucumber/lib/support_code_library_builder/types - ITestCaseHookParameter

    • @cucumber/cucumber/lib/runtime - IRuntimeOptions

Would it be possible for Cucumber.js to export the above classes, types, and functions, for example under reporters namespace (or something similar so that they don't get in the way of regular users):

import { reporters } from '@cucumber/cucumber';

reporters.TestCaseHookDefinition

Alternatively, would it be possible to revert those changes if the above proposal requires too much work?

Thanks,
Jan

bug

Most helpful comment

Okay, 7.2.1 is out with a revert, I'll dig back into the ESM thing and see if there's a way we can avoid this issue. Thanks for raising @jan-molak

All 4 comments

@jan-molak

It looks like support for ESM introduced in 7.2.0 (#1589) breaks a number of external reporters, as it no longer allows for sub-module imports.

Just to quickly clarify, this only occurs when using --esm, right?

I had noticed the issue with pretty as well today, I will look at the impact of expanding what we export on the main entry point. Most looks reasonable but we'll need to be careful as we're effectively adding new things to the API contract which undoing later would be a breaking change.

Hi @davidjgoss!

Just to quickly clarify, this only occurs when using --esm, right?

No, the issue occurs whenever an external project tries to import any sub-module from @cucumber/cucumber.

I've reproduced the issue here - https://github.com/jan-molak/cucumber-js-1646

git clone https://github.com/jan-molak/cucumber-js-1646.git
cd cucumber-js-1646
npm install
npm start

See error:

> [email protected] start /path/to/jan-molak/cucumber-js-1646
> node index.js

internal/modules/cjs/loader.js:438
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/models/test_case_hook_definition' is not defined by "exports" in /path/to/jan-molak/cucumber-js-1646/node_modules/@cucumber/cucumber/package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:513:3)
    at resolveExports (internal/modules/cjs/loader.js:432:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:472:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/path/to/jan-molak/cucumber-js-1646/index.js:1:32)

Okay, 7.2.1 is out with a revert, I'll dig back into the ESM thing and see if there's a way we can avoid this issue. Thanks for raising @jan-molak

Thanks for responding so quickly, @davidjgoss!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfstephe picture jfstephe  路  4Comments

NoNameProvided picture NoNameProvided  路  5Comments

lamartire picture lamartire  路  6Comments

travi picture travi  路  5Comments

dblooman picture dblooman  路  7Comments