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

139
Views
How to config jest to work with ES6 modules? Javascript

I'm using JEST for testing some javascript code in ES6 Modules. It looks like this:

import Block from "./block.js";

export default class Blockchain {
  constructor() {
    this.chain = [Block.genesis()];
  }

  addBlock({ data }) {
    const previousBlock = this.chain[this.chain.length-1];
    const newBlock = Block.mineBlock({ lastBlock:previousBlock, data });
    this.chain.push(newBlock);
  }
}

But when I executed the unit tests it appears the following message:

ReferenceError: module is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/mnt/c/Users/carlo/Documents/github-repos/blockchain_development/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

I'm using Babel for compiling the ES6 modules and the development script works perfectly. So the problem is related with Jest not being able to execute the ES6 Modules. If anyone can help me out with this I would appreciate it.

about 4 years ago · Juan Pablo Isaza
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!