Reputation: 21
I followed the react-email doc, and when I type the yarn email command I get this error:
$ email dev --port 3001
***\node_modules\ora\index.js:65
if (process.platform === 'win32') {
^
Error [ERR_REQUIRE_ESM]: require() of ES Module ***\node_modules\strip-ansi\index.js from ***\node_modules\ora\index.js not supported.
Instead change the require of ***\node_modules\strip-ansi\index.js in ***\node_modules\ora\index.js to a dynamic import() which is available in all CommonJS modules.
at mod.require (***\node_modules\next\dist\server\require-hook.js:65:28)
at Object.<anonymous> (***\Cutify\node_modules\ora\index.js:7:19)
at mod.require (***\node_modules\next\dist\server\require-hook.js:65:28)
at Object.<anonymous> (***\node_modules\react-email\cli\index.js:420:26) {
code: 'ERR_REQUIRE_ESM'
}
I tried to look at the doc or similar cases on issues but nothing relevant. If anyone has a solution
Upvotes: 1
Views: 412
Reputation: 376
Add a resolution in the package.json file to force strip-ansi
to version 6.0.0 or 6.0.1, as it was converted to pure ESM starting with version 7.0.0.
{
"resolutions": {
"strip-ansi": "6.0.0"
}
}
If you use npm, you can use an override instead:
{
"overrides": {
"strip-ansi": "6.0.0"
}
}
Upvotes: 0
Reputation: 22
I think this article might help.
const initEmailSystem = async () => {
if (process.platform === 'win32') {
await import('ora').then(oraPackage => {
const ora = oraPackage.default;
const spinner = ora('Initializing email system...').start();
setTimeout(() => {
spinner.succeed('Email system ready');
}, 1000);
});
} else {
console.log('Email system initialization skipped on non-Windows platform');
}
};
export default initEmailSystem;
Solving the React-Email ES Module Requirement Issue
Upvotes: -2