Cucumber-js: The "from" argument must be of type string. Received type undefined

Created on 10 Jun 2020  ·  6Comments  ·  Source: cucumber/cucumber-js

I am trying to use steps I wrote and publish on npm
Here is the error I have:

> cucumber-js e2e/src/**/*.feature --require ./node_modules/@myProject/uat/dist/*.step.js

TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received type undefined
at validateString (internal/validators.js:125:11)
at Object.relative (path.js:1162:5)
at getDefinitionLineAndUri (/home/myname/Documents/myProject/mysubProjectV2/node_modules/@myProject/uat/node_modules/cucumber/lib/support_code_library_builder/build_helpers.js:184:27)
at buildStepDefinitionConfig (/home/myname/Documents/myProject/mysubProjectV2/node_modules/@myProject/uat/node_modules/cucumber/lib/support_code_library_builder/build_helpers.js:124:7)
at SupportCodeLibraryBuilder.defineStep (/home/myname/Documents/myProject/mysubProjectV2/node_modules/@myProject/uat/node_modules/cucumber/lib/support_code_library_builder/index.js:51:79)
at Object.<anonymous> (/home/myname/Documents/myProject/mysubProjectV2/node_modules/@myProject/uat/dist/click.step.js:40:12)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at supportCodePaths.forEach.codePath (/home/myname/Documents/myProject/mysubProjectV2/node_modules/cucumber/lib/cli/index.js:142:42)
at Array.forEach (<anonymous>)
at Cli.getSupportCodeLibrary (/home/myname/Documents/myProject/mysubProjectV2/node_modules/cucumber/lib/cli/index.js:142:22)

I have found that this is this.cwd which is undefined. What can i do?
image

If I copy paste my steps in the root directory (where the package.json is), I don't have any error. So the problem is: I cannot not --require from node_modules.

Most helpful comment

any resolution for this issue? I am getting this error with Cucumber 7

All 6 comments

did you try from node_modules in your local directory ?

any resolution for this issue? I am getting this error with Cucumber 7

@stefdelec @VivekLande this is likely related to either

  • your steps package depending on a different version of cucumber than your host project
  • working locally with your steps package npm link'd

In either case you can end up with two different cucumber-js instances at runtime which can cause this (you could check this by looking in your node_modules hierarchy).

I'm working on documenting this in #1540 - take a look at the workaround and see if that works for you?

Thanks @davidjgoss, I am able to resolved the issue with the solution provided by you.

This workaround isn't working for me. I've definitely not got cucumber installed elsewhere. I've been on this for hours and I'm getting nowhere. This is my package json dependencies:

"dependencies": {
    "@cucumber/cucumber": "^7.0.0",
    "@cucumber/cucumber-expressions": "^12.0.0",
    "gherkin-testcafe": "^5.0.0",
    "testcafe": "^1.13.0"
  }

I've searched my node_modules folder and cucumber isn't in there multiple times. I've no idea where to go next

@csurfleet can you please create a minimal reproducible example?

Was this page helpful?
0 / 5 - 0 ratings