Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
0xkriswebchain opened this issue Jun 30, 2024 · 0 comments
Open

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

0xkriswebchain opened this issue Jun 30, 2024 · 0 comments
Labels

Comments

@0xkriswebchain
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant