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

225
Views
Cómo usar Node js Assert con Mocha en un proyecto de módulo ES6

Uso Node.js v14.17.0, Mocha 9.0.2. Mi proyecto es un proyecto básico configurado para usar el módulo ES6 js creado para comprender este problema.

 { "name": "mocha-tlp", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "mocha" }, "author": "", "license": "ISC", "type": "module" }

Con el caso de prueba ( test/foo.js ):

 import assert from 'assert/strict'; describe('MyObject', function () { describe('#myFunction()', function () { it('should work', function () { assert(true, "All good"); }); }); });

Obtuve el siguiente error :

 Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\xxxxxxxxxxxxxx\test\foo.js require() of ES modules is not supported. require() of C:\xxxxxxxxxxxxxx\test\foo.js from C:\xxxxxxxxxxxxxx\node_modules\mocha\lib\esm-utils.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 foo.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\projects\svelte\dgb-app\package.json.

No parece ser un problema que esm y mocha --require esm puedan resolver porque tanto Node.js como Mocha admiten ESM para esas versiones.

¿Cómo puedo usar Nodejs Assert con Mocha cuando proyecto ESM?

over 4 years ago · Santiago Trujillo
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!