const ethers = require("ethers");

const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/MYKEYISHERE')



const provider = new ethers.providers.JsonRpcProvider(`https://mainnet.infura.io/v3/MYKEYISHERE`)

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')

16 Answers 16


Look at this post.

EthersJS Listening to events with NodeJS Strange Errors

Had the same problem few days ago, turned out to be problem with a beta release of ethers.js.

The fix for me was to downgrade "ethers" to version 5.4 in the config.json, then remove node_modules folder and lastly npm install to install ethers again.

  • Thank you very much Commented Feb 7, 2023 at 12:41
  • 1
    Did not work for me.
    – Mansuu....
    Commented Sep 25, 2023 at 12:42

The newer version of Ethers seems to be unstable ethers 6.0.2... To solve this error downgrade your ethers version to 5.7.2 by going to your package.json

"ethers": "5.7.2"

now on your cli use npm install [email protected] or yarn add [email protected] depending on your package manager and that should solve your error.

  • Worked like a charm thank you Commented Jul 4, 2023 at 18:30

I am using ethers version 6.2.3, You can directly import it from ethers package.

const { ethers, JsonRpcProvider } = require('ethers');

For more info refer to this link https://github.com/ethers-io/ethers.js/issues/3924.

Entire code I am using to deploy contract locally using ethers on Ganache

//importing thers and JsonRpcProvider
const { ethers, JsonRpcProvider } = require('ethers');
const fs = require('fs-extra');
async function main() {
  // Json Rpc Provider - Connecting to local blockchain
  const provider = new JsonRpcProvider('address'); // add your rpc server url from Ganache

  // Connect to wallet to sign transactions
  const wallet = new ethers.Wallet(
    'Add your private key here',

  //Read ABI which you get post compilation using solc
  const abi = fs.readFileSync('./fileName.abi', 'utf8');
  //Read Binary which you get post compilation using solc
  const binary = fs.readFileSync(

  //Create Contract factory object to deploy
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  console.log('Deploying, Please wait...');
  // Deploy and you are good to go
  const contract = await contractFactory.deploy();

  .then(() => process.exit(0))
  .catch((error) => {


Deploying, Please wait...
BaseContract {
  target: '0x35aD58985b61f634A8108A7ffcF6D438ab701ffB',
  interface: Interface {
    fragments: [ [FunctionFragment], [FunctionFragment], [FunctionFragment] ],
    deploy: ConstructorFragment {
      type: 'constructor',
      inputs: [],
      payable: false,
      gas: null
    fallback: null,
    receive: false
  runner: Wallet {
    provider: JsonRpcProvider {},
    address: '0x8EDA89abFAB838dc350c12fA8b6D9Ad630380B2f'
  filters: {},
  fallback: null,
  [Symbol(_ethersInternal_contract)]: {}
  • One more thing to mention ethers version 6 is in Beta so you can downgrade to version 5 as well. Commented Mar 28, 2023 at 20:32

Had the same problem few days ago, turned out to be problem with a beta release of ethers.js.

The fix for me was to downgrade "ethers" to version 5.4 in the package.json, then remove node_modules folder and lastly npm install to install ethers again.



I also faced the same issue, when I changed the version it worked adequately. change the version (6.0.3 to 5.7.2). The latest version is not stable.


I had the same problem, the problem is in the version of the ethers, so I changed the version of ethers to ^5.7.2 in package.json Then I deleted the whole folder node_modules and again installed all components


There are some problems in the latest ether.js version. Change the ether version to 5.4.0 in the package.json file then delete node modules and reinstall it using npm install.


As mentioned in the hardhat-ethers plugin docs you must install 'ethers@^5.0.0' version and it resolves the issue.

  • thank you for mentioning the source of information. I was wondering why version 6.2.3 is not working.
    – oldpride
    Commented Apr 6, 2023 at 2:58

npm install [email protected]

const provider = new thers.providers.JsonRpcProvider("" );

option 2. Have latest version and in use

const { ethers, JsonRpcProvider } = require("ethers");
const provider = new JsonRpcProvider("")
  • With ethers@v5
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
  • With ethers@v6
const provider = new ethers.JsonRpcProvider(RPC_URL);

I think you will have to import JsonRpc provider at the beginning.

const { JsonRpcProvider } = require("ethers");
  • This didnt help.
    – Blissful
    Commented Mar 9, 2023 at 8:26

For this error

Cannot read properties of undefined (reading 'JsonRpcProvider')

run this command to solve this issue;

npm install --save-dev ethers@^5


yarn add --dev ethers@^5

I was facing a similar issue yesterday, what I did was to uninstall ethers and reinstall a lower version, particularly from 6.8 to 5.4.


This worked for me

step 1: open the terminal

yarn add ganache
yarn run ganache

step 2: Keep the ganche running and OPEN a NEW TERMINAL

node deploy.js

yarn add [email protected] and try it.... the new 6.x version of ether seems to be unstable



npm uninstall ethers

npm install --save-dev @nomiclabs/hardhat-ethers 'ethers@^5.0.0'

In hardhat.config.js


Not the answer you're looking for? Browse other questions tagged or ask your own question.