You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playwright+Cucumber报错:ReferenceError: exports is not defined

解决ES模块环境下Cucumber配置的exports错误

你遇到的ReferenceError: exports is not defined in ES module scope错误,是因为你的cucumber.mjs是ES模块文件(后缀为.mjs且项目启用了"type": "module"),却使用了CommonJS规范的module.exports语法,这在ES模块环境中不被支持。

修改cucumber.mjs文件,将CommonJS的导出语法替换为ES模块的导出语法即可:

const common = `
    features/**/*.feature
  --require setup/assertions.cjs
  --require setup/hooks.cjs
  --require step-definitions/**/*.steps.js
  --publish-quiet
  `;

export default {
    default: `${common} features/!**/!*.feature`
};

修改后再执行npm run test -- --tags "@Begin"命令,即可正常运行测试。

内容的提问来源于stack exchange,提问作者nosequeweaponer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 15:15:40