Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Playwright – Cucumber – ReferenceError: exports is not defined in ES module scope

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading