typescriptethers.jsts-node

cannot access ethers.js providers when using import statement in typescript


I am running typescript using ts-node and try to use ethers.js provider:

import { ethers } from "ethers";
const provider = new ethers.providers.JsonRpcProvider(url);

it gets the following error:

TSError: ⨯ Unable to compile TypeScript: - error TS2339: Property 'providers' does not exist on type 'typeof import

The code works using:

const ethers = require("ethers");

but I need es6 format to run the script since my other module run on es6, otherwise I have to convert all other dependencies to use "require" statement, which is too much.

ethers.js doc says that it can run on es6. Is it because I use ts-node?


Solution

  • according to this ethers.js closed issuethis is fixed by

    executing:

    const provider = new ethers.JsonRpcProvider();
    

    instead