Fri Feb 18 2022·2 min read
Photo by Blake Moulton
The chalk error "[ERR_REQUIRE_ESM]: require() not supported" occurs because the
chalk package has been converted to be an ESM only package in version
which means that the package cannot be imported with
To solve the chalk error "[ERR_REQUIRE_ESM]: require() not supported",
downgrade the version of the package to
4.1.2 by running the following
npm install firstname.lastname@example.org . This is the last version of
chalk that is
The recommendation in the
release notes of the
chalk package is that if you're using
chalk with TypeScript or a build tool
you should downgrade to version
To install version
4 of chalk, open your terminal in the root directory of
your project and run the following command.
npm install email@example.com
Now you are able to use the
chalk package with the
const chalk = require('chalk'); console.log(chalk.red('Hello world!!! 🎉🎉🎉'));
And here is the output I get in my terminal when I run the code from the snippet.
If your environment supports ES Modules, you should try to convert the
require() import to ESM.
import chalk from 'chalk'; console.log(chalk.red('Hello world!!! 🎉🎉🎉'));
But this might not work, depending on your setup.
The release notes of the
chalk package explicitly state that it's fine to stay on v4 for now as it has
been stable for years.
Note that if you use TypeScript with version less than
4.6, you should be
4.x. You can read more about this in this