All the configurations needed for Apex, LWC, Aura, and VF code formatting to work in Visual Studio code are automatically set up when you create a new Salesforce project with VS Code. This new project can be with or without the package.xml
file. But still, the code formatting doesn't work properly for Salesforce code, majorly Apex code.
Problem
The problem is that when the project is set up all the node Node modules used by VS Code are not installed in the project folder by default. That is why the formatting does not work properly.
Solution For Newly Setup Projects
- Check if your project has
package.json
file. - If the doesn't exist in your project folder then run the command on terminal
npm init
. If your VS code setup is correct then this file is generated at the time of project creation. If the file is already there in your project, no need to run this command, you can skip this step. - Now open a new terminal inside the vs code and run this command:
npm install
. This command installs all the dependent node packages required by the project based on thepackage.json
file. - If you run into any errors from the above command try running
npm audit fix
. - And you are done.
Solution For Existing Projects
If you have an existing project set up and code formatting is not working properly then follow the below steps.
- Make sure that you are able to see hidden files on your PC/Mac.
- Go to your project folder and look for the
node_modules
folder and delete it. - Now open a new terminal inside the vs code and run this command:
npm install
. This command installs all the dependent node packages required by the project based on thepackage.json
file. - If you run into any errors from the above command try running
npm audit fix
. - And you are done.
No comments :
Post a Comment
Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at rahul@forcetrails.com