Home > Software design >  Playwright - Cucumber - ReferenceError: exports is not defined in ES module scope
Playwright - Cucumber - ReferenceError: exports is not defined in ES module scope

Time:11-06

Hi people: Working on Playwright with Cucumber and Javascript I'm facing the next issue trying to run the framework.

ReferenceError: exports is not defined in ES module scope

This is my cucumber.mjs file:

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

module.exports = {
    default: `${common} features/!**/!*.feature`
};

The error message says that the expression "exports" causes this issue.

Please don't tell me that remove the "type": "module", from package.json.

By the way: I tried to run the framework with the next command:

npm run test -- --tags "@Begin" 

@Begin is a tag included in the Cucumber file.

Please, if you can help me with this. Thanks in advance!!!

CodePudding user response:

You're using CommonJS modules, so you should use the .cjs file extension, not the .mjs file extension.

.cjs: CommonJS, importing using require("adsf") and exporting using module.exports

.mjs: ES Modules, importing using import asdf from "asdf" and exporting using export default asdf

  • Related