Remix連接本地&遇到的問題
桌面版下載:https://github.com/ethereum/remix-desktop/releases
前提條件:安裝node (node版本不要太低,最好14+)
1.安裝remix
npm install -g @remix-project/remixd
2.建立remix與本地文件連接
remixd -s 具體文件項目路徑 --remix-ide http://remix.ethereum.org/
#方式1:從文件項目目錄下執(zhí)行該命令
remixd -s . --remix-ide http://remix.ethereum.org/
#方式2:指定具體文件路徑(如:)
remixd -s \Dev\Code\BlockChain\solidity --remix-ide http://remix.ethereum.org/
運行報錯:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: D:\Dev\Tool\nvm\v12.16.0\node_global\node_modules\@remix-project\remixd\node_modules\axios\index.js
require() of ES modules is not supported.
require() of D:\Dev\Tool\nvm\v12.16.0\node_global\node_modules\@remix-project\remixd\node_modules\axios\index.js from D:\Dev\Tool\nvm\v12.16.0\node_global\node_modules\@remix-project\remixd\src\bin\remixd.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from D:\Dev\Tool\nvm\v12.16.0\node_global\node_modules\@remix-project\remixd\node_modules\axios\package.json.
錯誤原因: node版本過低,node版本應>=14
解決方法:升級node版本(前提條件安裝nvm)
沒有安裝的可先安裝nvm,便于我們node版本管理:
下載地址:https://github.com/coreybutler/nvm-windows/releases
下載 nvm-setup.zip,解壓之后會有個.exe安裝程序,安裝即可。
1.安裝新版本node
# nvm install node版本號
# 可先執(zhí)行 nvm ls available,查看node版本信息,選擇要安裝的版本,我這里安裝的是16.17.0,命令如下:
nvm install 16.17.0
可使用 nvm ls命令查看本地已有版本,查看是否已經(jīng)安裝成功,安裝成功后會出現(xiàn)對應版本信息
2.切換版本
#nvm use 版本號
nvm use 16.17.0
至此node版本更新成功!
重新安裝remix: npm install -g @remix-project/remixd
運行報錯:‘npm’ 不是內(nèi)部或外部命令,也不是可運行的程序
或批處理文件。
錯誤原因: 安裝node時,未安裝npm
解決方法(簡單):
網(wǎng)上有很多參考方法,均可參考,在這提供一種簡單的參考方案:
1.訪問:https://nodejs.org/zh-cn/download/releases/ ,從官網(wǎng)中下載指定的版本的node以及npm,例如我安裝的是16.17.0版本,找到該版本,點擊下載即可
2.解壓下載好的文件,將里面的文件全部復制,粘貼到我們安裝node的目錄下(去找nvm安裝目錄,找到我們新安裝的node目錄,如v16.17.0是我新安裝的,當我們使用nvm命令安裝時,該目錄只有兩個文件,node-modules和node.exe,可先將其刪掉,然后將復制好的文件粘貼至該目錄下)
至此問題全部解決,重新運行remix與本地文件連接命令:
remixd -s \Dev\Code\BlockChain\solidity --remix-ide http://remix.ethereum.org/
運行成功:文章來源:http://www.zghlxwxcb.cn/news/detail-696572.html
3.打開remix(http://remix.ethereum.org/)
點擊connect to localhost連接本地
確認連接:
連接報錯: Cannot connect to the remixd daemon. Please make sure you have the remixd running in the background.
解決: 關掉remix頁面,重新打開,再連接后,連接成功
注意: 若還出現(xiàn)該問題報錯,注意查看訪問地址是不是https,將其改為http再嘗試文章來源地址http://www.zghlxwxcb.cn/news/detail-696572.html
到了這里,關于Remix連接本地&遇到的問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!