Bug Link: You cannot deploy a Salesforce Community to a Sandbox containing LWC and Experiences folders in the same deployment package.
Tl;dr
You need to run two deployments, one with LWC and the other with Experiences. Each cannot have the other in the deployment. Use .forceignore to hide the folders during each deployment.
Current Salesforce Setup
sfdx-cli/7.58.2-937f666ed4 win32-x64 node-v10.15.3
Salesforce Spring ‘20
Api Version 48.0
Let’s Set the Stage
For several months I’ve been developing successfully with Salesforce Community using the *.site file in the siteDotComSites folder. As many may or may not know this file contains all site configuration, but it is not human-readable. Salesforce responded to the need to manipulate the site configuration programmatically by creating the Experience Bundle. It’s expected that you begin relying on the Experience bundle for making changes to your Community environment instead of or in addition to the Community Builder. In my situation, when I don’t know how or where to make the change in the Experience files I make the change in the Builder and pull the changes to my local environment. The Experience files are updated with the changes. Slowly, I’m learning what changes need to be made and where.
What is confusing about this problem is that deployment to a development Scratch Org succeeds without issue. This bug only shows up when you are trying to deploy to the Dev Sandbox.
If you deploy with both LWC and Experience folders in the package you may receive an error response such as the following:
Don’t you love Salesforce’s very detailed error messages? :) It’s as clear as mud!
The solution lies in making two separate deployments, but it’s also how you make those deployments. 1) LWC must be deployed before Experiences. 2) .forceignore must exclude the relevant folder.
In Azure Pipelines, our CICD system, I created a Build task to modify the .forceignore file and add the Experiences folder paths to the file before calling “sfdx deploy”. After the first deploy I modify it again and replace Experiences with LWC. Then I call deploy again. Remember, .forceignore tells the compiler what to IGNORE, not what to include. So, Experiences first means LWC is included and vice-versa on the second deployment. Here’s what it looks like.
My .forceignore file has the following line at the bottom in VS Code.
Why not include the path from your development environment?
This is due to the human problem of forgetfulness. When I’m deploying to the Scratch Org in development there is no bug and if I include this in my unit testing I will forget to comment/ uncomment the line. Therefore, it is better to ignore the issue in development and handle it in the Build process.
I use “#$” as a placeholder for the Python task:
Notice I look for “#$” and replace it with the experiences folder path.
Then, in Powershell we call to validate our deployment:
Then I modify the .forceignore file again with another Python task:
I look for the experiences path and replace it with lwc.
I then deploy again in Powershell:
Here, I deploy only experiences. I can leave it as force-app, but it will take a little longer to deploy. If you try to deploy experiences WITHOUT modifying .forceignore it will not work. At least it didn’t for me.
Hope Salesforce fixes this bug soon.
Happy coding!