Contract-Deployment
錯誤:找不到模組“ganache-cli”
我對 JavaScript 和 Solidity 程式非常陌生,我正在嘗試從 Windows PowerShell 執行測試。
我打開我的 PowerShell 視窗並輸入
npm run test
我在哪裡得到錯誤
> inbox@1.0.0 test C:\inbox > mocha Error: Cannot find module 'ganache-cli' Require stack: - C:\inbox\test\Inbox.test.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Function.Module._load (internal/modules/cjs/loader.js:746:27) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:92:18) at Object.<anonymous> (C:\inbox\test\Inbox.test.js:2:17) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29) at ModuleJob.run (internal/modules/esm/module_job.js:169:25) at async Loader.import (internal/modules/esm/loader.js:177:24) at async formattedImport (C:\inbox\node_modules\mocha\lib\esm-utils.js:7:14) at async Object.exports.requireOrImport (C:\inbox\node_modules\mocha\lib\esm-utils.js:48:32) at async Object.exports.loadFilesAsync (C:\inbox\node_modules\mocha\lib\esm-utils.js:73:20) at async singleRun (C:\inbox\node_modules\mocha\lib\cli\run-helpers.js:125:3) at async Object.exports.handler (C:\inbox\node_modules\mocha\lib\cli\run.js:366:5) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! inbox@1.0.0 test: `mocha` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the inbox@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\ramic\AppData\Roaming\npm-cache\_logs\2021-06-23T08_06_56_286Z-debug.log PS C:\inbox>
我想我解決它的方法是
1-重新安裝最新版本的ganache,我用來部署我的合約的本地測試區塊鏈,開發我的應用程序以執行測試。
npm install ganache-cli@latest -g
2- 然後我重新安裝 Node Package Manager (npm),這是用於 JavaScript 程式的包管理器,使用
npm install
3-然後我使用
npm run test
注意:值得注意的是“npm 可以通過 package.json 文件在一個命令中安裝一個項目的所有依賴項”因此,重要的是還要查看 package.json 文件,看看是否有任何錯誤或錯誤的版本。