第 7 课:编译器版本错误 -> 10:43.16(完整的区块链可靠性课程)


$ /home/ionmind/hardhat-fundme-fcc/node_modules/.bin/hardhat deploy --network rinkeby
Error HH606: The project cannot be compiled, see reasons below.
These files import other files that use a different and incompatible version of Solidity:
* contracts/test/MockV3Aggregator.sol (^0.8.12) imports @chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol (^0.6.0)
To learn more, run the command again with --verbose
Read about compiler configuration at https://hardhat.org/config

在得到这个错误后,我按照视频

上的指示修改了hardhat.config.js文件
module.exports = {
//solidity: "0.8.12",
solidity: {
compilers: [{ version: "0.8.12" }, { version: "0.6.0" }],
},

但是仍然得到错误,所以我也修改了solhint.js文件中的编译器版本

{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "^0.8.12", "^0.6.0"],
"func-visibility": ["warn", { "ignoreConstructors": true }],
"var-name-mixedcase": "off",
"avoid-low-level-calls": "off"
}
}

但是仍然得到错误。

我在测试文件夹中创建了一个单独的AggregatorV2V3Interface文件,本地导入到MockV3Aggregator中。溶胶,还声明了每个文件的solidity版本^0.8.12

//SPDX-License-Identifier:MIT
pragma solidity ^0.8.12;
interface AggregatorInterface {
//Code Here//
}
interface AggregatorV3Interface {
//Code Here//
}
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.12;
import "./AggregatorV2V3Interface.sol";

代码中没有错误或警告,但我在尝试编译时仍然得到相同的错误。我不明白为什么我似乎是唯一一个有这个编译器问题的人。任何帮助都是感激的。谢谢你!

更新你的solid版本:

module.exports = {
//solidity: "0.8.12",
solidity: {
compilers: [{ version: "0.8.12" }, { version: "0.6.6" }],
},