Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
¿Por qué recibo este error UnhandledPromiseRejectionWarning cuando ejecuto npm build en mi proyecto sin servidor?

Recibo el siguiente error cuando intento ejecutar npm build en mi proyecto aws-nodejs-typescript sin servidor y no entiendo cómo solucionarlo. ¿Alguien puede señalarme en la dirección correcta, por favor?

 npm build (node:44390) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/local/lib/node_modules/npm/node_modules/chalk/source/index.js require() of ES modules is not supported. require() of /usr/local/lib/node_modules/npm/node_modules/chalk/source/index.js from /usr/local/lib/node_modules/npm/lib/utils/explain-dep.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/local/lib/node_modules/npm/node_modules/chalk/package.json. ...

¡Muchas gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La última versión de chalk ha cambiado a la sintaxis de importación/exportación de ES6 en lugar de CJS (CommonJS con require ). Así que en lugar de:

 const chalk = require('chalk');

Tu tienes que hacer:

 import chalk from 'chalk';

(Desafortunadamente) también tendrá que cambiar todos los demás requisitos a importaciones, luego cambiar todas sus exportaciones de module.exports a export default y todas sus exports.whatever . lo que sea para export whatever; donde sea lo que sea, o como se sugiere, cambie el nombre de su archivo a index.cjs para forzar CJS.

Luego están los documentos para importar y exportar si los necesita.

Luego, debe agregar el type: "module" a package.json. Tanto para la tiza :)

No me gustaba eso, así que solía usar colores en su lugar, pero...

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!