Cucumber-js: “from”参数必须是字符串类型。 接收类型未定义

创建于 2020-06-10  ·  6评论  ·  资料来源: cucumber/cucumber-js

我正在尝试使用我在 npm 上编写和发布的步骤
这是我的错误:

> 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)

我发现这是未定义的this.cwd 。 我能做什么?
image

如果我将我的步骤复制粘贴到根目录(package.json 所在的位置)中,我就没有任何错误。 所以问题是:我不能不 --require 来自 node_modules。

最有用的评论

这个问题的任何解决方案? 我在使用 Cucumber 7 时遇到此错误

所有6条评论

您是否尝试从本地目录中的 node_modules ?

这个问题的任何解决方案? 我在使用 Cucumber 7 时遇到此错误

@stefdelec @VivekLande这可能与

  • 您的步骤包取决于与您的宿主项目不同的黄瓜版本
  • 在本地使用您的步骤包npm link 'd

在任何一种情况下,您都可能在运行时得到两个不同的黄瓜 js 实例,这可能会导致这种情况(您可以通过查看node_modules层次结构来检查这一点)。

我正在#1540 中对此进行记录 - 查看解决方法,看看它是否适合您?

谢谢@davidjgoss ,我能够使用您提供的解决方案解决问题。

这种解决方法对我不起作用。 我绝对没有在其他地方安装黄瓜。 我已经做了几个小时了,但一无所获。 这是我的包 json 依赖项:

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

我已经搜索了我的 node_modules 文件夹,并且多次没有黄瓜。 我不知道下一步要去哪里

@csurfleet你能创建一个最小的可重现示例吗?

此页面是否有帮助?
0 / 5 - 0 等级