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

The "from" argument must be of type string. Received type undefined #1326

Closed
stefdelec opened this issue Jun 10, 2020 · 13 comments · Fixed by #1540
Closed

The "from" argument must be of type string. Received type undefined #1326

stefdelec opened this issue Jun 10, 2020 · 13 comments · Fixed by #1540

Comments

@stefdelec
Copy link

stefdelec commented Jun 10, 2020

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.

@jonathanwork
Copy link

did you try from node_modules in your local directory ?

@VivekLande
Copy link

VivekLande commented Jan 16, 2021

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

@davidjgoss
Copy link
Contributor

davidjgoss commented Jan 20, 2021

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

@VivekLande
Copy link

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

@csurfleet
Copy link

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

@charlierudolph
Copy link
Member

@csurfleet can you please create a minimal reproducible example?

@phatNfqAsia
Copy link

In my case,
Import a cucumber step-implementation module in a normal es module file (e.g index.ts) will lead to error: TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined
So the solution is to extract the logic and export normal functions from a different non-cucumber-related file

@aurelien-reeves
Copy link
Contributor

@phatNfqAsia could you please give more info on your issue?
You seem to mention modules: are those EcmaScript modules?
What are your depenencies and versions? Would you have a repo where you would reproduce that issue with a minimal setup?

@phatNfqAsia
Copy link

@aurelien-reeves my repo is kept private so I can not share, sorry :(
My issue is when I am trying to call some API of @cucumber/cucumber with ts-node instead of cucumber-js command.
In fact I don't need to use it, the program throw error because I accidentally import one file that refer to that cucumber package.
So I detach the logic inside the to-import file, make sure it does not contain any cucumber reference and then my code start working.

@aurelien-reeves
Copy link
Contributor

Ok, thanks for the details.

When I asked for a repo, that could be a reproduction repo made simple without confidential data. As simple as possible to reproduce the issue

@vcardins
Copy link

Wondering why this issue was closed. Still happening

@aurelien-reeves
Copy link
Contributor

As requested before, would you have a minimal reproducible example?
That would help us helping you with this issue

@VictorVermeulen
Copy link

VictorVermeulen commented Apr 28, 2022

Wondering why this issue was closed. Still happening

https://github.com/cucumber/cucumber-js/blob/HEAD/docs/transpiling.md Did you try this?

For us, the above link was not the solution. We removed the package.json and node modules from the bdd test folder, and imported everything from the ''general'' package.json. Why it now works is still a mystery to me (since other folders in our project have their own package.json without issues) but figured it might help others to mention this here.

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

Successfully merging a pull request may close this issue.

10 participants