在 MS Code 中,此导入不会突出显示为错误:
import { keccak256 } from "ethers/lib/utils";
但是当我尝试
yarn start
时,它会产生错误。
[1] ✘ [ERROR] Could not resolve "ethers/lib/utils"
[1]
[1] ../util/eth.ts:1:26:
[1] 1 │ import { keccak256 } from "ethers/lib/utils";
[1] ╵ ~~~~~~~~~~~~~~~~~~
[1]
[1] The path "./lib/utils" is not exported by package "ethers":
[1]
[1] ../node_modules/ethers/package.json:67:13:
[1] 67 │ "exports": {
[1] ╵ ^
[1]
[1] You can mark the path "ethers/lib/utils" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
我不明白
package.json
中的导入意味着什么以及如何将其与代码一起使用,这样 code
和 yarn start
都会满意。
确保您安装了 Ethers 库的最新版本。