[SalesForce] Lightning Web Component: A required metadata folder named “lwc” does not exist in this workspace

I am trying to perform this(https://trailhead.salesforce.com/content/learn/projects/quick-start-lightning-web-components/create-a-hello-world-lightning-web-component) with VS code and it is throwing following error.
A required metadata folder named "lwc" does not exist in this workspace.

Performed following steps.

  • Installed lightning web component plugin in VS code.
  • Created a new SFDX project.
  • Error while running SFDX: Create Lightning Web Component.

Best Answer

For now, you need to have the pre-release version installed for DX:

sfdx plugins:install salesforcedx@pre-release

Make sure you've also updated all extensions, including Lightning Web Components, which is not currently part of the Salesforce Extension Pack.

Often, simply restarting after installing/updating all extensions and the pre-release sfdx plugin will automatically create the lwc folder for you. You may also need to close and re-open the folder for it to take effect. I'm not sure how/why my lwc folder appeared, but it wasn't obvious as to what I did.

If all else fails, create a new project in a new, empty directory, and copy the lwc folder back into force-app/main/default/, so that it has two files:

./force-app/main/default/lwc/.eslintrc.json
./force-app/main/default/lwc/jsconfig.json

Once you've done that, you'll stop getting that error and be able to create new components. These config files may require modification if you copy from a new project, so make sure you check the file paths of jsconfig.json. Every time you create a new component with sfdx, jsconfig.json will be updated with more metadata, so make sure you commit this file if you're using a repo.

NOTE: Even though you'll be able to create files locally, to push to the server, you need a pre-release org for now, since all new LWC features are tied to API 45.0 and later, while all production and scratch orgs will be 44.0.