sitecore Habitat - TypeError: Cannot read property '0' of undefined

When you get the error TypeError: Cannot read property '0' of undefined in the Gulp task '05-Sync-Unicorn' you probably don't have a SharedSecret configured in the file C:\Projects\Habitat\src\Project\Habitat\code\App_Config\Include\Unicorn\Unicorn.UI.config.

In my project the SharedSecret wat commented out, i.e.:

<!--<SharedSecret></SharedSecret> Uncomment this line and provide a strong randomized shared secret here. At least 64 characters is recommended, for example https://www.grc.com/passwords.htm -->

I followed the instructions, uncommented it, grabbed a 64 characters password from  https://www.grc.com/passwords.htm so my line read:

<SharedSecret>06A3203AA36C84D499D9BF6F79852B61EF2992465C2160FE09263E1AB5B882E2</SharedSecret>

I did run gulp 05-Sync-Unicorn again, but still the same error. 

After adding a line to the script C:\Projects\Habitat\scripts\unicorn.js:

console.log("Reading Unicorn configuration file " + unicornConfigFile);
var data = fs.readFileSync(unicornConfigFile);
I saw my problem:
The script is reading from the deployed website location ( C:\websites\Habitat.dev.local\Website/App_config/Include/Unicorn/Unicorn.UI.config), not the project location (C:\Projects\Habitat\src\Project\Habitat\code\App_Config\Include\Unicorn\Unicorn.UI.config). 
I could run the complete gulp default task again, but doing a Publish... on the Sitecore.Habitat.Website project (right-click on the project) does the job much quicker.
After publishing, re-execute step 5 again: gulp 05-Sync-Unicorn
Hint for the sitecore team: reading a configuration setting using the line:
secret = result.configuration.sitecore[0].unicorn[0].authenticationProvider[0].SharedSecret[0];
from a configuration file where this setting is commented out will lead to issues that take people a lot of time to find out, especially because I couldn't find anything on this on the Wiki documentation of the Habitat project.

No Comments