While trying to utilize ethers.js provider in my TypeScript project using ts-node, I encountered the following issue:
import { ethers } from "ethers";
const provider = new ethers.providers.JsonRpcProvider(url);
The error message displayed was:
TSError: ⨯ Unable to compile TypeScript: - error TS2339: Property 'providers' does not exist on type 'typeof import
Switching to the following code made it work:
const ethers = require("ethers");
However, I prefer using the es6 format for consistency with other modules. If I stick to the es6 format, I would have to convert all other dependencies to use the "require" statement, which seems like a daunting task.
According to the ethers.js documentation, it should be compatible with es6 syntax. Could this issue be caused by my use of ts-node?