Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in 7.2.0 break external reporters #1646

Closed
jan-molak opened this issue Apr 21, 2021 · 14 comments
Closed

Changes in 7.2.0 break external reporters #1646

jan-molak opened this issue Apr 21, 2021 · 14 comments
Labels
🐛 bug Defect / Bug

Comments

@jan-molak
Copy link
Member

jan-molak commented Apr 21, 2021

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 Breaks with @cucumber/cucumber v7.2.0 cucumber-js-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

jan-molak added a commit to serenity-js/serenity-js that referenced this issue Apr 21, 2021
Cucumber 7.2.0 introduced breaking changes, so I'm dropping the version range for now. See
cucumber/cucumber-js#1646
@davidjgoss
Copy link
Contributor

davidjgoss commented Apr 21, 2021

@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.

@davidjgoss davidjgoss added the 🐛 bug Defect / Bug label Apr 21, 2021
jan-molak added a commit to jan-molak/cucumber-js-1646 that referenced this issue Apr 21, 2021
@jan-molak
Copy link
Member Author

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:

> cucumber-js-1646@1.0.0 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)

@davidjgoss
Copy link
Contributor

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

jan-molak added a commit to serenity-js/serenity-js that referenced this issue Apr 21, 2021
Cucumber 7.2.0 introduced a breaking change, which 7.2.1 has reverted. See cucumber/cucumber-js#1646
@jan-molak
Copy link
Member Author

Thanks for responding so quickly, @davidjgoss!

@abhinavchaudharyventures

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
Hi @davidjgoss I am again facing the same issue with cucumber version 7.2.1 . could you pls help here .

2021-11-26T08:26:07.081Z ERROR @wdio/local-runner: Failed launching test session: Error: Couldn't initialise "@wdio/cucumber-framework".
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/formatter/helpers/event_data_collector' is not defined by "exports" in C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\cucumber-framework\node_modules@cucumber\cucumberpackage.json

@aurelien-reeves
Copy link
Contributor

Hi @abhinavchaudharyventures,

Are you able to make it work with a version of cucumber < 7.2.0? 7.1.0 for example?
And what about 8.0.0-rc.1?

The error reported looks like it is related to ESM support (I thing an error not defined by "exports" is related to modules). But cucumber v7.2.1 does not support ESM at all. ESM for user support code is now supported as part of cucumber@8.0.0-rc.1. But cucumber itself is still not a module.

Are you trying to use the formatter/helpers/event_data_collector by yourself? Or is it related to @wdio? Do you have a reproducible example?

Would you mind open a dedicated issue? I don't think it is related to this one despite the error message looking the same

@abhinavchaudharyventures

Hi @aurelien-reeves
Yes i have tried with cucumber version 7.1.0 as well & with 8.0.0-rc.1 as well but getting same error.

I am not using formatter/helpers/event_data_collector by myself in code anywhere and while executing tests in wdio i am getting below error.

2021-11-26T08:57:44.265Z WARN @wdio/utils:shim: You are running tests with @wdio/sync which will be discontinued starting Node.js v16.Read more on webdriverio/webdriverio#6702
2021-11-26T08:57:44.852Z INFO @wdio/local-runner: Run worker command: run
2021-11-26T08:57:46.783Z ERROR @wdio/local-runner: Failed launching test session: Error: Couldn't initialise "@wdio/cucumber-framework".
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/formatter/helpers/event_data_collector' is not defined by "exports" in C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\cucumber-framework\node_modules@cucumber\cucumber\package.json
at throwExportsNotFound (internal/modules/esm/resolve.js:285:9)
at packageExportsResolve (internal/modules/esm/resolve.js:491:3)
at resolveExports (internal/modules/cjs/loader.js:444:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:484:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:818:27)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\cucumber-framework\build\index.js:48:48)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at safeRequire (C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\utils\build\utils.js:184:16)
at safeRequire (C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\utils\build\utils.js:187:15)
at initialisePlugin (C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\utils\build\initialisePlugin.js:30:50)
at Runner.run (C:\Users\abhinav.c.chaudhary\Documents\TYLAutomationsuite\tyl-e2e\node_modules@wdio\runner\build\index.js:82:56)

@aurelien-reeves
Copy link
Contributor

A reproducible example would be really helpful here

Which version of wdio are you using? Did you asked their support?

@davidjgoss
Copy link
Contributor

Given the file path of the error:

node_modules@wdio\cucumber-framework\node_modules@cucumber\cucumber\package.json

This suggests that @wdio/cucumber-framework depends on a specific version of cucumber and you might need to bump that rather than have a dependency in your own package?

@jan-molak
Copy link
Member Author

jan-molak commented Nov 30, 2021

I think those imports in the wdio-cucumber-framework are relevant:

import EventDataCollector from '@cucumber/cucumber/lib/formatter/helpers/event_data_collector'
import { ITestCaseHookParameter } from '@cucumber/cucumber/lib/support_code_library_builder/types'
import { IRuntimeOptions } from '@cucumber/cucumber/lib/runtime'

I've mentioned those and other useful (from a framework developer's perspective ;) ) imports in the original post.

wdio-cucumber-framework depends on Cucumber 8.0.0-rc1.

Hope this helps

@davidjgoss
Copy link
Contributor

@jan-molak thanks! Those deep imports should be working in 8.0.0-rc1, it's just the package.json that we missed which is being fixed via #1870 and should be in the next RC (that should fix your issue @abhinavchaudharyventures, sorry for the delay in confirming).

ITestCaseHookParameter and IRuntimeOptions are now on the entry point after some recent changes, but yeah I think EventDataCollector makes sense to be on there too, I'll look at doing that soon.

@abad786
Copy link

abad786 commented Jan 26, 2022

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:

> cucumber-js-1646@1.0.0 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)

Hi Davidjgoss, I am facing the same issue. have you resolved this issue? if yes, please let me know the solution of it because I am stuck in this and need to deliver the sprint.

@aurelien-reeves
Copy link
Contributor

@abad786 the issue you have quoted has been fixed. Please make a try updating cucumber to 7.2.1 or to 8.0.0-rc.2

@abhinavchaudharyventures

@abad786 the issue you have quoted has been fixed. Please make a try updating cucumber to 7.2.1 or to 8.0.0-rc.2

Thanks @aurelien-reeves and team for fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

5 participants