Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
chalk - Error [ERR_REQUIRE_ESM]: require() of ES Module

Hi tried to install chalk on my very simple app and then i got error:

Error [ERR_REQUIRE_ESM]: require() of ES Module my-file-is-here  and chalk\node_modules\chalk\source\index.js from my-file-is-here not supported.
Instead change the require of index.js in my-file-is-here to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (`my-file-is-here`) {
  code: 'ERR_REQUIRE_ESM'
}

thats my code:

const os = require("os")
const chalk = require("chalk")

console.log("app running")
over 4 years ago · Santiago Trujillo
6 Respostas
Responde à pergunta

0

Think it's ES module and works in import way, but you can do something like this:

const { chalk } = require("chalk");

It worked for me when I worked with firebase in v8 style.

over 4 years ago · Santiago Trujillo Relatório

0

//First Change in you Package.json

"main": "app.js",
"type": "module",//use this line 

//Second change in App.js

import os from 'os' //  const os = require("os")

import chalk from 'chalk';//const chalk = require("chalk")
over 4 years ago · Santiago Trujillo Relatório

0

Chalk 5 has changed to ESM. They provide a link to better understand what that means: Pure ESM.

From chalk README:

IMPORTANT: Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now.

As of this reply, the last version of chalk 4 is 4.1.2.

over 4 years ago · Santiago Trujillo Relatório

0

That is something to do with the version you are using which is I think 5.0.0

  1. npm uninstall chalk

then

  1. npm i chalk@2.4.1

now you can run your code

const chalk = require('chalk');
console.log(chalk.blue('Hello world!')); 
over 4 years ago · Santiago Trujillo Relatório

0

Add "type": "module" to your package.json. Replace "main": "index.js" with "exports": "./index.js" in your package.json. Update the "engines" field in package.json to Node.js 12: "node": "^12.20.0 || ^14.13.1 || >=16.0.0". Remove 'use strict'; from all JavaScript files. Replace all require()/module.export with import/export. Use only full relative file paths for imports: import x from '.'; → import x from './index.js';. If you have a TypeScript type definition (for example, index.d.ts), update it to use ESM imports/exports. Optional but recommended, use the node: protocol for imports.

over 4 years ago · Santiago Trujillo Relatório

0

Step-1 npm uninstall chalk (delete all chalk files)


Step-2 npm install chalk@4.1.0

const chalk = require("chalk");
console.log(chalkl.green("Hello"));

Done🙌🏻

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda