我正在使用 ts-node 运行 typescript 并尝试使用 ethers.js 提供程序:
import { ethers } from "ethers";
const provider = new ethers.providers.JsonRpcProvider(url);
出现以下错误:
TSError: ⨯ Unable to compile TypeScript: - error TS2339: Property 'providers' does not exist on type 'typeof import
代码的工作原理是:
const ethers = require("ethers");
但是我需要 es6 格式来运行脚本,因为我的其他模块在 es6 上运行,否则我必须将所有其他依赖项转换为使用“require”语句,这太多了。
ethers.js 文档说它可以在 es6 上运行。是因为我使用了ts-node吗?
最佳答案
关于typescript - 在 typescript 中使用 import 语句时无法访问 ethers.js 提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75659064/