【发布时间】:2023-02-25 07:29:50
【问题描述】:
我有一个 email.js 文件,它有一个名为 email_func 的函数,我想在 cypress.config.js 文件内的“after:run”块中调用该函数。但是当我尝试导入时出现以下错误
Your configFile is invalid: D:\Cypress-automation\cypress-automation\cypress.config.js
It threw an error when required, check the stack trace below:
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'D:\Cypress-automation\cypress-automation\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
在 email.js 文件中,我在下面导出了
const email_var = new emailClass();
module.exports = email_var;
在 cypress.config.js 中,我正在尝试像这样导入,但没有运气
const email_var = require('./cypress/support/email');
【问题讨论】:
标签: javascript cypress es6-modules