Skip to content

Error [ERR_REQUIRE_ESM]: require() of ES Module  #6672

Open
@0xkriswebchain

Description

@0xkriswebchain

Lesson

Lesson 6

Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")

No response

Operating System

Windows

Describe the bug

While unit testing for Raffle.test.js `const { assert } = require("chai")
const { network, deployments, ethers, getNamedAccounts } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper-hardhat-config")

!developmentChains.includes(network.name)
? describe.skip
: describe("Raffle", function () {
let raffle, vrfCoordinatorV2Mock // , deployer

      beforeEach(async () => {
          const { deployer } = await getNamedAccounts()
          await deployments.fixture(["all"]) // Deploys modules with the tags "mocks" and "raffle"
          raffleContract = await ethers.getContract("Raffle", deployer) // Returns a new connection to the Raffle contract
          vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer) // Returns a new connection to the VRFCoordinatorV2Mock contract
          raffle = raffleContract.connect(player) // Returns a new instance of the Raffle contract connected to player
      })

      describe("constructor", function () {
          it("initializes the raffle correctly", async () => {
              const raffleState = (await raffle.getRaffleState()).toString()
              assert.equal(raffleState, "0")
              assert.equal(
                  interval.toString(),
                  networkConfig[network.config.chainId]["keepersUpdateInterval"],
              )
          })
      })
  })

` I got an error on An unexpected error occurred:

Error [ERR_REQUIRE_ESM]: require() of ES Module. It says hardhat-lottery-project/node_modules/chai/chai.js from from hardhat-lottery-project/test/unit/Raffle.test.js not supported. Instead change the require of chai.js in /home/krischain/hardhat-free-codecamp/hardhat-lottery-project/test/unit/Raffle.test.js to a dynamic import() which is available in all CommonJS modules.
at Object. (/home/krischain/hardhat-free-codecamp/hardhat-lottery-project/test/unit/Raffle.test.js:1:20) {
code: 'ERR_REQUIRE_ESM'
} I used different dynamic import, even changed the syntax, or type: module. but still the error is coming again and again. Anybody knows about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions