macos truffle Error: Failed to fetch the Solidity compiler from the following locations

20 篇文章 0 订阅
11 篇文章 1 订阅

Error: Failed to fetch the Solidity compiler from the following locations: 问题解决

背景:学习区块链 做truffle测试
环境: macos
执行命令工具: webstorm 自带的 terminal , vscode自带terminal

创建了truffle project ,并unbox了truffle demo 代码以后,执行truffle test 进行测试的时候,报出如下错误:

 truffle-test % truffle test ./test/metacoin.js

Compiling your contracts...
===========================
Error: Failed to fetch the Solidity compiler from the following locations: https://relay.trufflesuite.com/solc/emscripten-wasm32/,https://binaries.soliditylang.org/emscripten-wasm32/,https://relay.trufflesuite.com/solc/emscripten-asmjs/,https://binaries.soliditylang.org/emscripten-asmjs/,https://solc-bin.ethereum.org/bin/,https://ethereum.github.io/solc-bin/bin/. Are you connected to the internet?


    at VersionRange.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:183:1)
    at Generator.next (<anonymous>)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:8:1
    at new Promise (<anonymous>)
    at exports.modules.780.__awaiter (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:4:1)
    at VersionRange.getSolcFromCacheOrUrl (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:174:1)
    at VersionRange.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:206:1)
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:5:43)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Truffle v5.7.3 (core: 5.7.3)
Node v18.8.0

之前找解决方案时,一直思路就锁死在solc的版本的原因上,一直没有解决这个问题。今天又遇到这个问题于是再续前缘,继续翻文档。

看到一篇文章:https://stackoverflow.com/questions/73355583/error-failed-to-fetch-the-solidity-compiler

里面有这么一句

You should never run sudo as suggested by the above answer. Although it will work, it exposes your PC to attack since you give admin privileges to these packages.

Instead, you should run npm doctor to check your node environment health. This should fix the problem.

这让我猛然想起,这会不会是权限的原因?于是我就在truffle test 命令前加了sudo,结果真的正常执行了。

truffle-test % sudo truffle test
Password:

Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol-bin. Attempt #1
> Compiling ./contracts/MetaCoin.sol
> Compiling ./test/TestMetaCoin.sol
> Artifacts written to /tmp/test--89619-j5IzAXeNl5w1
> Compiled successfully using:
   - solc: 0.8.13+commit.abaa5c0e.Emscripten.clang
⠼ Fetching solc version list from solc-bin. Attempt #1
✓ Downloading compiler. Attempt #1.
  TestMetaCoinc version list from solc-bin. Attempt #1
    ✔ testInitialBalanceUsingDeployedContract (74ms)#1
    ✔ testInitialBalanceWithNewMetaCoin (49ms)tempt #1
✓ Downloading compiler. Attempt #1.
  Contract: MetaCoin
    ✔ should put 10000 MetaCoin in the first account (62ms)
    ✔ should call a function that depends on a linked library (72ms)
    ✔ should send coin correctly (121ms)in. Attempt #1
✓ Downloading compiler. Attempt #1.

  5 passing (4s)

然后我突然想起来之前破解某个工具的时候,脚本在iterm2里无法执行,只能在macos自带的terminal中执行的一个情况,于是我又打开macos自带的terminal ,无需sudo也可以正常执行。接着又试了试 iterm2,也能正常执行。也许webstorm和vscode自带的terminal有什么权限的问题。

下次如果遇到不能正常执行的情况,也可以换换思路,使用其他终端尝试一下,也许有意外惊喜。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值