cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.02k stars 1.09k forks source link

Invalid installation false positives on Windows #2353

Open MiladSadinam opened 8 months ago

MiladSadinam commented 8 months ago

👓 What did you see?

When I try to start a scenario on a Windows 11 machine (using the VSCode CucumberOpen.cucumber-official extension) I get the following error message:

> plano-cucumber-playwright@1.0.0 debug
> cross-env PWDEBUG=1 DEBUG=pw:api cucumber-js --name Send a marketing gift-card

`publishQuiet` option is no longer needed, you can remove it from your configuration; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md
Error: 
          You're calling functions (e.g. "When") on an instance of Cucumber that isn't running.
          This means you have an invalid installation, mostly likely due to:
          - Cucumber being installed globally
          - A project structure where your support code is depending on a different instance of Cucumber
          Either way, you'll need to address this in order for Cucumber to work.
          See https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations

    at checkInstall (C:\Users\admin\Desktop\Dr_Plano\scheduler.frontend.ng2\ui-tests\node_modules\@cucumber\cucumber\src\support_code_library_builder\index.ts:127:15)
    at C:\Users\admin\Desktop\Dr_Plano\scheduler.frontend.ng2\ui-tests\node_modules\@cucumber\cucumber\src\support_code_library_builder\index.ts:145:11
    at Object.<anonymous> (C:\Users\admin\Desktop\Dr_Plano\scheduler.frontend.ng2\ui-tests\features\app\booking-system-settings\gift-card-sale\pos-sync\boulderado.steps.ts:13:5)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (c:\Users\admin\Desktop\Dr_Plano\scheduler.frontend.ng2\ui-tests\node_modules\ts-node\src\index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (c:\Users\admin\Desktop\Dr_Plano\scheduler.frontend.ng2\ui-tests\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
> ERROR: Command exited with status code 1.

✅ What did you expect to see?

The scenario should be started locally.

📦 Which tool/library version are you using?

The problem happens on cucumber-js 10.0.0. If I go back to version 9.6.0 the problem does not exist. Also, the problem seems to be Window specific. We have it on two Windows machines. On two other Mac machines, the problem does not exist.

🔬 How could we reproduce it?

If needed, I can provide a minimalistic project to reproduce it.

📚 Any additional context?

I tried to rule out all causes described in https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations. I believe none of them is the case for me.

@cucumber/cucumber is not globally installed.

Result of npm why @cucumber/cucumber is:

@cucumber/cucumber@10.0.0
node_modules/@cucumber/cucumber
  @cucumber/cucumber@"10.0.0" from the root project
  peer @cucumber/cucumber@">=7.0.0" from @cucumber/pretty-formatter@1.0.0
  node_modules/@cucumber/pretty-formatter
    @cucumber/pretty-formatter@"1.0.0" from the root project

We are using @cucumber/cucumber in our whole project, and I believe we don't use npm link.

davidjgoss commented 8 months ago

Looking at the command

cross-env PWDEBUG=1 DEBUG=pw:api cucumber-js --name Send a marketing gift-card

This could be picking up a global install if you have one. Can you run npm list -g to find out? Can you also prepend npx to the invocation of cucumber-js which should cause it to look locally first?

MiladSadinam commented 8 months ago

npm list -g does not contain cucumber-js. I added npx to the command, but the same error occurs.

davidjgoss commented 8 months ago

One more thing to check, can you do npm why cucumber to ensure you don't have the legacy cucumber package in there somehow?

If needed, I can provide a minimalistic project to reproduce it.

I think this would be the best next step.

MiladSadinam commented 7 months ago

@davidjgoss I will provide more information. But, I think it will happen start of next year. Sorry for the delay.

Pawel-Zygler commented 7 months ago

Anyone found a solution?

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 3 weeks with no activity. Remove the stale label or comment or this will be closed in another 5 days.

MiladSadinam commented 6 months ago

We are currently on it to analyze the reason for the error. It seems to be related to the VSCode AbhinabaGhosh.cucumberquick extension we are using to execute the scenarios. We will follow up again soon.

ruimendes29 commented 5 months ago

@davidjgoss In the folder I provided I used the project sugested in the cucumber starting guide, so it is as simple as it gets, and if I change the version of @cucumber/cucumber to 10.3.1 I get the reported issue, but I change back to 9.6.0 the issue is gone. As already mentioned this only happens when I run the scenario using the AbhinabaGhosh.cucumberquick extension. hellocucumber.zip

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 3 weeks with no activity. Remove the stale label or comment or this will be closed in another 5 days.

m4rtelli commented 4 months ago

We are running into a similar situation when running any version of Cucumber 10.0 in our CLI. With 9.6.0, we have no issues. I can confirm that 'npm why @cucumber/cucumber' yields only a single version of the package inside the product. If I run our project locally via the same command, it's fine. But in CLI, we receive the error mentioned in the description. @cucumber/cucumber is installed as a dependency and we are calling 'npx cucumber-js' to execute our tests.

Happy to provide additional info. At the moment, our CLI works fine with cucumber 9.6.0 but fails with any version of 10.0. Thanks!

davidjgoss commented 4 months ago

@m4rtelli thanks for reporting you have this issue too. Would you be able to run in your CI with debug turned on and see what's different in the debug output between 9.6.0 and 10.0.0? Also, are you using Windows?

m4rtelli commented 4 months ago

@m4rtelli thanks for reporting you have this issue too. Would you be able to run in your CI with debug turned on and see what's different in the debug output between 9.6.0 and 10.0.0? Also, are you using Windows?

Hi @davidjgoss - thank you so much for the response. We are using Windows and with debug mode enabled, I see no difference in the resolved configuration. No mention of Cucumber being installed globally, either. Thanks!

m4rtelli commented 4 months ago

@m4rtelli thanks for reporting you have this issue too. Would you be able to run in your CI with debug turned on and see what's different in the debug output between 9.6.0 and 10.0.0? Also, are you using Windows?

To add onto my previous reply, given the same machine which we trigger our CI from, why would the result of this condition be different with v10.0.0+ versus v9.6.0? https://github.com/cucumber/cucumber-js/blob/5a4f129fdb7020e1bc9c1a539a3cea93307881b8/src/support_code_library_builder/index.ts#L126

If i revert immediately back to 9.6.0 and re-run the job on the same Windows machine, it runs fine.

davidjgoss commented 4 months ago

That's a reasonable point @m4rtelli. The check on this.cwd was a heuristic, since we expect it to be present in a correctly-running instance of Cucumber. This makes me think there is another issue at play which this check and error is masking. I've made a change and released 10.3.2 so we have a status field especially for this. I don't expect this to necessarily fix your issue, but please do give it a try and let's see if we get a different error we can learn from.

m4rtelli commented 4 months ago

That's a reasonable point @m4rtelli. The check on this.cwd was a heuristic, since we expect it to be present in a correctly-running instance of Cucumber. This makes me think there is another issue at play which this check and error is masking. I've made a change and released 10.3.2 so we have a status field especially for this. I don't expect this to necessarily fix your issue, but please do give it a try and let's see if we get a different error we can learn from.

Hi @davidjgoss - apologies for the delay. It took some time for the new version to be made available for me internally. Installed the build and I am seeing the updated error message: You're calling functions (e.g. "When") on an instance of Cucumber that isn't running (status: PENDING). This means you may have an invalid installation, potentially due to:

davidjgoss commented 4 months ago

Thanks again @m4rtelli

In an effort to pin this down, I've created a repro project at https://github.com/davidjgoss/cucumber-js-2353-repro. This is the most basic example (pretty much per our readme) with debug logging enabled. I've added GitHub actions to run it on both Linux and Windows with all our supported Node.js versions - nothing failing so far. But I'd encourage anyone affected to clone this repo and see if you can get it to fail either locally or in your CI setup, and feel free to do a pull request with those changes that make it fail.

In the meantime, the changes from 9.6.0 -> 10.0.0 are kind of obscured by a wholesale reformatting of imports, but in terms of meaningful changes, the possible culprits would be:

I'll keep digging into this from my side.

m4rtelli commented 3 months ago

@davidjgoss Unfortunately internally we are restricted from cloning repo's outside of our own instance of GitHub. But I'll try and replicate this and run it locally and through CI. Will report back if I am successful. Thanks!

m4rtelli commented 3 months ago

I gave version 10.4 a try. Didn't notice any of the additional logging if that helps narrow this down a bit. Thanks for all of your help.

m4rtelli commented 3 months ago

Some additional context. In my CI run, I consoled out npm list with a higher depth and confirmed that cucumber is not installed globally and there is only one version as well. This is very puzzling considering a local run on a VM is successful but in CI, on that same VM it fails. Definitely calling a local copy of cucumber in my pipeline. Mystery 😂

gotvatter commented 3 months ago

Hi @davidjgoss I am having the same error on mac when upgrading to @cucumber/cucumber@9.6.0

I followed https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations. I believe none of them is the case for me. -@cucumber/cucumber is not globally installed. -Result of npm why @cucumber/cucumber is: @cucumber/cucumber@9.6.0 dev node_modules/@cucumber/cucumber dev @cucumber/cucumber@"^9.6.0" from the root project

I tried to delete all possible packages that would need old cucumber, verified package.lock.json as well The only cucumber left is cucumber 6.0.5 that it is already included in WDIO node_modules as dev dependency.

I tried to debug cucumberJS code itself : I get undefined for this.cwd: if ((0, value_checker_1.doesNotHaveValue)(this.cwd)) {

image

image

I guess I need to understand if I use

For API: @cucumber/cucumber@9.6.0 and For mobile: WDIO 6 with cucumber 6.0.5 that comes with WDIO in its node_modules, theoretically I should be fine? Why WDIO would use @cucumber/cucumber@9.6.0, not its own cucumber 6.0.5 from its node_modules!

Can anyone help with this issue

vijaydashore13 commented 2 months ago

I had similar issue mentioned above when trying to upgrade @cucumber to 10.6.0. I had to force cucumber to point current directory and use it from there.

const importCwd = require('import-cwd')
const { Given, When, Then } = importCwd('@cucumber/cucumber')

This seems to be an issue for version 10 and above. Do we know if this is going to be resolve in upcoming versions?

fgiraldi commented 2 months ago

Same here when running CI with Jenkins and Windows agents. Cucumber v9.6.0 works perfect in all scenarios. Cucumber v10.6.0 runs seamleslly in local machine and locally on EC2 instance, but when triggered via Jenkins agent, that "You're calling functions (e.g. "When") on an instance of Cucumber that isn't running (status: PENDING). This means you may have an invalid installation, potentially due to:" message shows up. Solution provided by @vijaydashore13 worked perfectly, but I think this should be considered just as a workaround, right?

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 3 weeks with no activity. Remove the stale label or comment or this will be closed in another 5 days.

MiladSadinam commented 1 month ago

Commenting to prevent the issue from being closed because of staleness.

davidjgoss commented 1 month ago

As of 10.8.0, there is some additional logging when running in debug mode at the start of the run, which should look something like:

Running cucumber-js 10.8.0 
Working directory: /Users/davidgoss/Projects/my-project
Running from: /Users/davidgoss/Projects/my-project/node_modules/@cucumber/cucumber/lib/api 

For an affected run, this should be useful to contrast with the paths shown in the "invalid installation" error. If anyone affected is able to capture this and report either here or via DMs in Slack, that would be really helpful.

(I've still not been able to reproduce this myself in Windows environments I have access to, but I'm continuing to try things.)

davidjgoss commented 1 month ago

@gotvatter I think you have more of a WDIO issue there. But you can't have cucumber and @cucumber/cucumber coexisting in the same project because they'll both expect to own the cucumber-js command in bin.

@vijaydashore13 nice workaround, thanks for posting that!

github-actions[bot] commented 4 weeks ago

This issue is stale because it has been open for 3 weeks with no activity. Remove the stale label or comment or this will be closed in another 5 days.

fgiraldi commented 4 weeks ago

No stale for us yet you bot!

ruimendes29 commented 2 weeks ago

@davidjgoss When running on debug I get the error: image and the following is also logged: image They seem to be using the same cucumber installation, I check and I don't have any other instance of cucumber installed