Cannot deploy ERC721 Upgradeable smart contract for NFT Marketplace

Hello everyone I am trying to deploy my ERC721Upgradeable NFT Marketplace Smart Contracts in the local hardhat network but I am getting a error regarding it. I am using Openzeppelin's Upgradeable smart contracts to build the contract. Can anyone help me figure out what I need to do in ordr to make the contract deployment work?

:1234: Code to reproduce

This is my config file:

require('@nomiclabs/hardhat-ethers');
require('@openzeppelin/hardhat-upgrades');

module.exports = {
  defaultNetwork: "hardhat",
  networks: {
    hardhat: {
    },
  },
  solidity: {
    version: "0.8.10",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
};

This is my error which I am getting after running the deployment command:

An unexpected error occurred:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/utils' is not defined by "exports" in D:\Work\Marketplace-Contracts\node_modules\ethers\package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:496:3)
    at resolveExports (internal/modules/cjs/loader.js:450:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:27)
    at Function.Module._load (internal/modules/cjs/loader.js:743:27)
    at Module.require (internal/modules/cjs/loader.js:965:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\Work\Marketplace-Contracts\node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy.ts:4:1)      
    at Module._compile (internal/modules/cjs/loader.js:1076:30) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

:computer: Environment

These are my dependencies:

"dependencies": {
    "@openzeppelin/contracts-upgradeable": "^4.8.1"
  },
  "devDependencies": {
    "@ethersproject/abi": "^5.7.0",
    "@ethersproject/providers": "^5.7.2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.8",
    "@nomicfoundation/hardhat-toolbox": "^2.0.1",
    "@nomiclabs/hardhat-ethers": "^2.2.2",
    "@nomiclabs/hardhat-etherscan": "^3.1.6",
    "@openzeppelin/hardhat-upgrades": "^1.22.1",
    "@typechain/ethers-v5": "^10.2.0",
    "@typechain/hardhat": "^6.1.5",
    "chai": "^4.3.7",
    "ethers": "^6.0.8",
    "hardhat": "^2.11.1",
    "hardhat-gas-reporter": "^1.0.9",
    "solidity-coverage": "^0.8.2",
    "typechain": "^8.1.1"
  }

Than you for your help.

One solution to the problem that I have found is using previous versions of ethers.js. Here I was using ethers version - 6.0.8 which I have later changed to 5.4.0

Here is my updated package.json file -

{
  "name": "web3",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "hardhat": "^2.12.7"
  },
  "devDependencies": {
    "@ethersproject/abi": "^5.7.0",
    "@ethersproject/providers": "^5.7.2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.8",
    "@nomicfoundation/hardhat-toolbox": "^2.0.1",
    "@nomiclabs/hardhat-ethers": "^2.2.2",
    "@nomiclabs/hardhat-etherscan": "^3.1.6",
    "@openzeppelin/hardhat-upgrades": "^1.22.1",
    "@typechain/ethers-v5": "^10.2.0",
    "@typechain/hardhat": "^6.1.5",
    "chai": "^4.3.7",
    "ethers": "^5.4.0",
    "hardhat-gas-reporter": "^1.0.9",
    "solidity-coverage": "^0.8.2",
    "typechain": "^8.1.1"
  }
}

If anybody have a solution feel free to let me know.

Hardhat and our Hardhat plugin are not yet compatible with Ethers v6. Please use Ethers v5.

1 Like

Yes I did the same and now the project is working fine.