如何在黄瓜中使用打字稿路径别名? [英] How to use typescript Path aliases in Cucumber?

查看:64
本文介绍了如何在黄瓜中使用打字稿路径别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在使用路径别名的项目中使用Cucumber.导入路径别名模块之一后,我会收到错误消息

I need to use Cucumber in a project that uses path aliasing. As soon as I would import one of the path aliased modules, I get an error

我已经在此 answer 中尝试了解决方案,但遇到了另一个问题:每当使用

I have tried solution in this answer, but I am running into another problem: Whenever I use the

   --require-module tsconfig-paths/register \

部分,我突然得到

    TypeError: cucumber_1.Given is not a function

每当我尝试运行功能时,都会出现

错误.

error whenever I try to run the features.

(错误变为 TypeError:给定的不是函数当我使用 const {Given} = require('cucumber')语法)

(The error changes to TypeError: Given is not a function when I use the const { Given } = require('cucumber') syntax)

在Cucumber中是否还有其他解决路径别名的方法,或者是否有解决不是功能问题的解决方案?

Is there any other solution for path aliasing in Cucumber, or is there a fix to the is not a function problem?

推荐答案

原来,我在根目录下使用 cucumber.js 文件作为配置,这会干扰 tsconfig-paths/register: tsconfig 然后从黄瓜" 而不是黄瓜模块中获取 cucumber.js 文件作为.

Turns out I was using cucumber.js file at root as config, which was interfering with tsconfig-paths/register: tsconfig then picked up the cucumber.js file for from 'cucumber', instead of the cucumber module.

因此解决方法是改为将所有-require-module 选项写入命令行

So the fix is to write all the --require-module options to the command line instead

这篇关于如何在黄瓜中使用打字稿路径别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆