ESM Module Support

Important

ESM module support 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 favor of ECMAScript module syntax:

import {x} from 'y'

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

testcafe chrome test.js --esm

Additional Requirements

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.