ESM Module Support

Warning

This article describes an experimental capability. Feel free to try it out and share your feedback with the TestCafe team. Do not use experimental capabilities for business-critical tasks — you may encounter bugs and lack of stability.

Important

ESM module suppport only works with Node.js 16 and up. Tests with ECMASCript module syntax are subject to additional requirements.

TestCafe has always used CommonJS syntax for module imports:

const { x } = require('y');

An increasing number of Node.JS packages abandon CommonJS in favour of ECMAScript module syntax:

import {x} from 'y'

Enable the --experimental-esm CLI flag to import modules that do not support CommonJS.

testcafe chrome test.js --experimental-esm

Additional Reuqirements

To run tests with ECMAScript import statements, make sure that your project meets at least one of the following requirements:

  1. The value of the type key in your project’s package.json file is module.
  2. The test files in your project use the .mjs extension.