I am doing this trailhead module to get started with testing in LWC.

The first step is to run below command

sfdx force:lightning:lwc:test:setup

But when I run this in terminal, I am getting a below error.

ERROR running force:lightning:lwc:test:setup: npm command not found. Verify npm is properly installed and try again.

I have verified npm is installed in my system, below is the screenshot.

enter image description here

enter image description here

as an alternate I downloaded jest library from git

but now not sure how to use this library in my current project so that I can run the next command

node node_modules/@salesforce/sfdx-lwc-jest/bin/sfdx-lwc-jest

Can someone please suggest on this, I have tried the same thing in different machines and all of them are failing with the same error.

  • Do you have nodejs installed. Just type node in CMD or terminal and see what it says.
    – manjit5190
    Jun 28, 2020 at 6:05
  • thank you for your response, I have updated my question.
    – gs650x
    Jun 28, 2020 at 6:08
  • Can you try and run npm in some other folder just to check if it is installed globally ? Maybe switch to documents folder and try npm version there.
    – manjit5190
    Jun 28, 2020 at 6:28
  • 1
    Yes, I have tried running in other folders as well, npm -- version works all the time.
    – gs650x
    Jun 28, 2020 at 6:30

2 Answers 2


faced same problem try following , it worked for me. npm install @salesforce/sfdx-lwc-jest --save-dev

  • 1
    Optionally, with --global to apply it to all projects.
    – sfdcfox
    Jun 28, 2020 at 17:33

I'm running into the same issue. When executing npm from the VSCode console, VSCode finds it - but when attempting to run sfdx force:lightnin:lwc:test:setup, VSCode reports it cannot find it:

Can find npm but then cannot find npm

So I ran npm install @salesforce/sfdx-lwc-jest --save-dev from windows cmd. That completed with 3149 vulnerabilities reported (none of which could be fixed with npm audit fix - I'm not sure if this is a problem).

Then I could run the unit tests from VSCode.

How does one get around the error in the screenshot though? I have npm on OS path.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .