Insights

Sitecore SXA Theme Setup On Docker Error

"Cannot Read Property '1' Of Null"

The Problem

While trying to create a new theme using the CLI, we reach the step asking if we "want to setup theme config file?" and the process comes to a screeching halt. We are presented a very non-helpful error:


PS C:\Source\test> sxa new MyTheme
? The theme will be created for instance based on url http://localhost/. Do you want to specify a different url? no
? Enter your login sitecore\admin
? Enter your password [hidden]
? Specify theme path. Root is Themes folder(format ) CustomThemePath
? Do you want to set up theme config file? yes
C:\Users\Anton\AppData\Roaming\nvm\v10.15.1\node_modules\@sxa\CLI\util\serverRequests.js:26
                    _6bc‍.g.console.log(chalk.bold.red(body.match(/<li>([\d\w\s\.]*)<\/li>/)[1]))
                                                                                            ^
TypeError: Cannot read property '1' of null
    at Request.request [as _callback] (C:\Users\Anton\AppData\Roaming\nvm\v10.15.1\node_modules\@sxa\CLI\util\serverRequests.js:26:93)
    at Request.self.callback (C:\Users\Anton\AppData\Roaming\nvm\v10.15.1\node_modules\@sxa\CLI\node_modules\request\request.js:188:22)
    at Request.emit (events.js:189:13)
    at Request.EventEmitter.emit (domain.js:441:20)
    at Request. (C:\Users\Anton\AppData\Roaming\nvm\v10.15.1\node_modules\@sxa\CLI\node_modules\request\request.js:1171:10)
    at Request.emit (events.js:189:13)
    at Request.EventEmitter.emit (domain.js:441:20)
    at IncomingMessage. (C:\Users\Anton\AppData\Roaming\nvm\v10.15.1\node_modules\@sxa\CLI\node_modules\request\request.js:1091:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15)
	

This is apparently due to the js failing to parse out the error and give us the details we actually need to debug the issue.

What is actually happening is that a "404 - File or directory not found" error is being thrown.

The Solution

We will need to enable a config file on the cm image to allow for SPE services to upload files. You can run the following code ad hoc in a Powershell terminal:


docker exec -it docker-sxa-node_cm_1 powershell
cd C:\inetpub\wwwroot\App_Config\Include\z.Feature.Overrides
Get-Item -Path .\z.SPE.Sync.Enabler.Gulp.config.disabled | Rename-Item -NewName z.SPE.Sync.Enabler.Gulp.config
exit


However, I would strongly recommend adding this to your cm's Dockerfile. This would mean that if you need to recreate image, it will happen as part of the build process. Also, you will be saving future developers who may pick up this repo from going through this same pain.

The purpose of the if statement is that this will fail on the second run once the file has been updated.


# Enable SPE services to allow file upload (for SXA Theme)

RUN cd C:\inetpub\wwwroot\App_Config\Include\z.Feature.Overrides
RUN if (Test-Path -Path .\z.SPE.Sync.Enabler.Gulp.config.disabled) { Get-Item -Path .\z.SPE.Sync.Enabler.Gulp.config.disabled | Rename-Item -NewName z.SPE.Sync.Enabler.Gulp.config }

If There Are Still Issues

I have seen it mentioned that the User you are using for SXA CLI (in our case sitecore/admin) may also need to inherit the sitecore\PowerShell Extensions Remoting role. I had done this first during my investigation into this issue but it made no difference, I still saw the error.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet Mike Payne

Development Team Lead

🎶🚴‍♂️⛰

Mike is a Development Team Lead who is also Sitecore 9.0 Platform Associate Developer Certified. He's a BCIS graduate from Mount Royal University and has worked with Sitecore for over seven years. He's a passionate full-stack developer that helps drive solution decisions and assist his team. Mike is big into road cycling, playing guitar, working out, and snowboarding in the winter.

Connect with Mike