导入在代码中有效,但在`yarn start`中不起作用

问题描述 投票:0回答:1

在 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
都会满意。

javascript node.js typescript import yarnpkg
1个回答
0
投票

确保您安装了 Ethers 库的最新版本。

© www.soinside.com 2019 - 2024. All rights reserved.