You need to sign in to do that
Don't have an account?
Sfdx can't find npm
I'm currently working on the Trailhead unit Set Up Jest Test Framework (https://trailhead.salesforce.com/content/learn/modules/test-lightning-web-components/set-up-jest-testing-framework?trail_id=build-lightning-web-components)
I am in the directory with my project and I'd like to install Jest into the project.
However, Sfdx seems unable to find npm even though it is clearly installed:
What is wrong and how can I fix it?
I am in the directory with my project and I'd like to install Jest into the project.
However, Sfdx seems unable to find npm even though it is clearly installed:
D:\tutorials\SFDC2020\Summer20>npm --version 6.14.5 D:\tutorials\SFDC2020\Summer20>sfdx force:lightning:lwc:test:setup ERROR running force:lightning:lwc:test:setup: npm command not found. Verify npm is properly installed and try again.
What is wrong and how can I fix it?
For all the Trailhead issues please report it here,
https://trailhead.salesforce.com/help?support=home#
https://trailhead.salesforce.com/help
So that our trailhead support engineers will look into it and get back to you.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Regards,
Salesforce Support.
And I have checked the Error internally and below are my findings,
Either try to install using sfdx force:lightning:lwc:test:setup or if you are trying to use npm directly, you can install sfdx-lwc-jest (https://www.npmjs.com/package/@salesforce/sfdx-lwc-jest)instead of lwc-jest, see the page you referred https://www.npmjs.com/package/@salesforce/lwc-jest
This package, @salesforce/lwc-jest, has been renamed to @salesforce/sfdx-lwc-jest. Please update your projects to reference @salesforce/sfdx-lwc-jest. @salesforce/lwc-jest will continue to be updated through the Winter '20 release, then development and releases will only happen against @salesforce/sfdx-lwc-jest.
I hope this helps.
No, refreshing the page several times did not help.
I did, however, open up Inspect and I can several instances of ERR_ABORTED 499 and "Failed to load resource: the server responded with a status of 499 () , which seems to be a very non-standard status code.
Very curious that the install instructions on npmjs.com are trying to tell me to use yarn. :-p
With loglevel=TRACE, you see the number of line in the javascript file that fails.
Finally, this command launched by the script that also fails can be launched directly:
The call to npm with child_process_1.spawnSync fails
setup.js (found with loglevel=TRACE )
With this technique, you can solve all these problems under windows linked with sfdx (the Trailhead team probably only uses Linux, that is insufficient of course)
npm is slow and many people prefer yarn.
sfdx force:lightning:lwc:test:setup encapsulates many checks and that works for "node" but not for "npm". It is not logical and it is a problem on windows especially.
The recommended commands are:
But that is not enough (still blocked)
setup.js > you can change it directly ( javascript + node ) On windows, you have probably two installations of node and you can uninstall the "exe" installation in conflct with the npm version above.
node -v often gives an old windows "exe" installation instead of the latest version above (14.4)..
"message": "Error installing @salesforce/sfdx-lwc-jest: 'spawnSync npm ENOENT'",
First solution at the top of this post:
npm install --save-dev @salesforce/sfdx-lwc-jest
That is not the same latest version via npm (v12 instead of v14)
C:\>node -v
v12.18.1
C:\>npm -v
6.14.5
C:\>npm install sfdx-cli --global
+ sfdx-cli@7.63.0
added 47 packages from 40 contributors, removed 39 packages, updated 67 packages and moved 6 packages in 345.76s
First solution is still:
npm install --save-dev @salesforce/sfdx-lwc-jest
I ran
from terminal in VS Code and it installed successfully as verified by
The package page is here:
https://www.npmjs.com/package/@salesforce/sfdx-lwc-jest (https://www.npmjs.com/package/@salesforce/sfdx-lwc-jest" target="_parent)