1

I am very new to programming in JavaScript and Solidity and I am trying to run a test from Windows PowerShell.

In my folder, I have all these files enter image description here

I open my PowerShell window and I typed

npm run test

Where I got the error of

> 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

I think the way I solved it was by

1- Re-installing the latest version of ganache, the local test blockchain that I use to deploy my contract, develop my application in order to run the test.

npm install ganache-cli@latest -g

2- Then I re-install Node Package Manager (npm), the package manager for the JavaScript programming using

npm install

3- Then I run the test using

npm run test

Note: It is worth noting that "npm can install, in one command, all the dependencies of a project through the package.json file" Therefore, it is important to also look at the package.json file and see if there were any errors or wrong versions.

1

Install ganache-cli in the directory by running the command npm i ganache-cli.

0

This is another one you don't need anything to do just type it and It must be worked.

npx ganache-cli

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.