no código:
//const chalk = require('chalk');
import chalk from 'chalk';
//import { createRequire } from 'fs';
const fs = require('fs');
//import fs from 'fs';
function pegaArquivo(caminhoDoArquivo) {
const enconding = 'utf-8';
fs.readFile(caminhoDoArquivo, enconding, (_, texto) => {
console.log(chalk.green(texto));
})
}
pegaArquivo('./arquivos/texto1.md');
Apresenta o erro:
file:///C:/Users/xxx/Documents/Node.js/Iniciais/index.js:4
const fs = require('fs');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Users\xxx\Documents\Node.js\Iniciais\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///C:/Users/xxx/Documents/Node.js/Iniciais/index.js:4:12
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Node.js v18.16.1