3

I am trying to create Unlocked package with LWC components. When I do so, I am getting error for naming it in Camel case.

Although, if I change the folder name from 'Notifier' to 'notifier' (without 'N' in caps, it works). Can I never use capital names for my components? or is it a best practice?

sfdx force:package:version:create -p notifier -d force-app -k test --wait 10 -v ping.skp-6xj1@force.com
Request in progress. Sleeping 30 seconds. Will wait a total of 600 more seconds before timing out. Current Status='InProgress'
ERROR:  markup://c:Notifier: LWC1116: Illegal folder name "Notifier". The folder name must start with a lowercase character: "notifier".
3

For Aura Components, the best practice has always been to use camelCaseNames. This is now enforced in Lightning Web Components. Note that the camelCaseName will be written in kebab-case in the template. For example, a helloWorld component will be put in a template as <c-hello-world></c-hello-world>. This is enforced by the Web Components Standard, and is not specific to LWC. The documentation specifies a lot of naming rules that must be followed:

  • Must begin with a lowercase letter (edit: now specifies lowercase)
  • Must contain only alphanumeric or underscore characters
  • Must be unique in the namespace
  • Can’t include whitespace
  • Can’t end with an underscore
  • Can’t contain two consecutive underscores
  • Can’t contain a hyphen (dash)

And also states:

Use camel case to name your component myComponent. Camel case component folder names map to kebab-case in markup. In markup, to reference a component with the folder name myComponent, use <c-my-component>.

  • 1
    I think its again a missing documentation. It would have been good to explicitly specify this as well in the naming rules list something as Should not start with an uppercase. You realize this only when you get further in the documentation where it mentions about camelCase for components. – Jayant Das Feb 6 at 21:27
  • @JayantDas Even better, they could just have said: Must begin with an lowercase letter. – sfdcfox Feb 6 at 21:31
  • Yeah true. Sometimes you overthink while constructing things :) – Jayant Das Feb 6 at 21:38
  • right..makes sense...so its a standard for LWC development – San Tosh Feb 7 at 11:28
  • 1
    The docs have been updated. – bonehelmet Feb 11 at 23:14

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.