matter-labs / hardhat-zksync

Apache License 2.0
279 stars 227 forks source link

`TypeError: Cannot convert undefined or null to object` #1174

Closed pcaversaccio closed 4 months ago

pcaversaccio commented 4 months ago

After upgrading to the latest package versions, I face the following error at compilation time:

Solidity 0.8.26 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.

Learn more at https://hardhat.org/hardhat-runner/docs/reference/solidity-support

Downloading zksolc 1.5.0
zksolc version 1.5.0 successfully downloaded
Downloading zkvm-solc 0.8.26-1.0.1
zkvm-solc version 0.8.26-1.0.1 successfully downloaded
Compiling contracts for zkSync Era with zksolc v1.5.0 and zkvm-solc v0.8.26-1.0.1
Compiling 3 Solidity files
Compiling contracts for zkSync Era with zksolc v1.5.0 and zkvm-solc v0.8.26-1.0.1
Compiling 3 Solidity files
An unexpected error occurred:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at extractLinkReferences (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\@openzeppelin+upgrades-core@1.34.1\node_modules\@openzeppelin\upgrades-core\src\link-refs.ts:14:31)
    at validate (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\@openzeppelin+upgrades-core@1.34.1\node_modules\@openzeppelin\upgrades-core\src\validate\run.ts:172:51)
    at OverriddenTaskDefinition._action (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\@openzeppelin+hardhat-upgrades@3.1.1_@nomicfoundation+hardhat-ethers@3.0.6_ethers@6.13.1_buff_mhf5jz5hfjjr3rvyeyogiw372a\node_modules\@openzeppelin\hardhat-upgrades\src\index.ts:124:25)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Environment._runTaskDefinition (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\hardhat@2.22.5_bufferutil@4.0.8_ts-node@10.9.2_@types+node@20.14.6_typescript@5.4.5__typescri_y7l26aazsthdkqjins4ibic3zy\node_modules\hardhat\src\internal\core\runtime-environment.ts:359:14)
    at async Environment.run (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\hardhat@2.22.5_bufferutil@4.0.8_ts-node@10.9.2_@types+node@20.14.6_typescript@5.4.5__typescri_y7l26aazsthdkqjins4ibic3zy\node_modules\hardhat\src\internal\core\runtime-environment.ts:192:14)
    at async SimpleTaskDefinition.action (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\hardhat@2.22.5_bufferutil@4.0.8_ts-node@10.9.2_@types+node@20.14.6_typescript@5.4.5__typescri_y7l26aazsthdkqjins4ibic3zy\node_modules\hardhat\src\builtin-tasks\compile.ts:1024:37)
    at async Environment._runTaskDefinition (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\hardhat@2.22.5_bufferutil@4.0.8_ts-node@10.9.2_@types+node@20.14.6_typescript@5.4.5__typescri_y7l26aazsthdkqjins4ibic3zy\node_modules\hardhat\src\internal\core\runtime-environment.ts:359:14)
    at async Environment.run (C:\Dev\Blockchain\hardhat-project-template-ts\node_modules\.pnpm\hardhat@2.22.5_bufferutil@4.0.8_ts-node@10.9.2_@types+node@20.14.6_typescript@5.4.5__typescri_y7l26aazsthdkqjins4ibic3zy\node_modules\hardhat\src\internal\core\runtime-environment.ts:192:14)

Use this repo for reproduction: https://github.com/pcaversaccio/hardhat-project-template-ts. Invoke pnpm install, uncomment zksync: true in the hardhat.config.ts, and compile with hardhat compile --force.

I'm not 100% sure yet if it's related to https://github.com/matter-labs/hardhat-zksync/issues/240 and https://github.com/matter-labs/hardhat-zksync/issues/998, that's why I open a new issue.

kiriyaga commented 4 months ago

Hello @pcaversaccio ,

The issue arises because tenderly, as a dependency, imports @openzeppelin/hardhat-upgrades, which invokes the validate function. Since the hardhat-zksync-upgradable plugin is not imported into your project, it generates an error. To resolve this, add hardhat-zksync-upgradable as a dependency and import it into your hardhat.config.ts file. This will make the compilation work. However, note that hardhat-zksync-upgradable only supports OpenZeppelin v4, whereas your project uses OpenZeppelin v5, so the plugin will not work properly (but compilation will be successful). The best approach is not to import @tenderly/hardhat-tenderly when using a zkSync network (e.g., add a flag to decide when to import the package and when not to). Doing so should resolve the issue.