I cannot get a simple theme to work: “Cannot read property ‘push’ of undefined”

Hi guys,

I had an old theme (made for version 0.7.x I think) and I wanted to update it. When I tried to install it I got all sort of errors about helper changes. I’ve made all the changes, except some errors I did not understand about CSS class names from “styles”.

After fixing the helper names, I still cannot activate the theme. It silently fails. Below is the error message I get in the logs (I don’t know what the problem is)
I think it might be that the GSCAN fails but doesn’t know how to report the error properly.

What do you make of this? I thought it should be pretty simple to make a Ghost theme

thanks,
John

{
“name”: “Log”,
“hostname”: “My-PC”,
“pid”: 14452,
“level”: 50,
“req”: {
“meta”: {
“requestId”: “19e64a30-9f55-11e9-b0b6-3f74d7d7bfc1”,
“userId”: “1”
},
“url”: “/themes/my-theme/activate/”,
“method”: “PUT”,
“originalUrl”: “/ghost/api/v2/admin/themes/my-theme/activate/”,
“params”: {},
“headers”: {
“host”: “localhost:2368”,
“connection”: “keep-alive”,
“content-length”: “2”,
“origin”: “http ://localhost:2368”,
“app-pragma”: “no-cache”,
“user-agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36”,
“content-type”: “application/json; charset=UTF-8”,
“accept”: “application/json, text/javascript, /; q=0.01”,
“x-requested-with”: “XMLHttpRequest”,
“x-ghost-version”: “2.25”,
“alexatoolbar-alx_ns_ph”: “AlexaToolbar/alx-4.0.3”,
“referer”: “http ://localhost:2368/ghost/”,
“accept-encoding”: “gzip, deflate, br”,
“accept-language”: “en-US,en;q=0.9,nl;q=0.8,ro;q=0.7”,
“cookie”: “REDACTED
},
“query”: {}
},
“res”: {
“_headers”: {
“x-powered-by”: “Express”,
“cache-control”: “no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0”,
“access-control-allow-origin”: “http ://localhost:2368”,
“vary”: “Origin, Accept-Encoding”,
“content-type”: “application/json; charset=utf-8”,
“content-length”: “210”,
“etag”: “W/“d2-SpGmqyRe9HHP2mDDS+M9w1lfUSE””
},
“statusCode”: 500,
“responseTime”: “111ms”
},
“err”: {
“id”: “19f6ec00-9f55-11e9-b0b6-3f74d7d7bfc1”,
“domain”: “http ://localhost:2368/”,
“code”: null,
“name”: “InternalServerError”,
“statusCode”: 500,
“level”: “normal”,
“message”: “Cannot read property ‘push’ of undefined”,
“stack”: “InternalServerError: Cannot read property ‘push’ of undefined\n at new GhostError (C:\Workspace\NodeJS\ghost\versions\2.25.4\core\server\lib\common\errors.js:10:26)\n at _private.prepareError (C:\Workspace\NodeJS\ghost\versions\2.25.4\core\server\web\shared\middlewares\error-handler.js:43:19)\n at Layer.handle_error (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\layer.js:71:5)\n at trim_prefix (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:315:13)\n at C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:284:7\n at Function.process_params (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:335:12)\n at next (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:275:10)\n at Layer.handle_error (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\layer.js:67:12)\n at trim_prefix (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:315:13)\n at C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:284:7\n at Function.process_params (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:335:12)\n at next (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:275:10)\n at C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:635:15\n at next (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\index.js:260:14)\n at next (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\express\lib\router\route.js:127:14)\n at apiImpl.then.then.catch (C:\Workspace\NodeJS\ghost\versions\2.25.4\core\server\api\shared\http.js:97:17)\n at tryCatcher (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\util.js:16:23)\n at Promise._settlePromiseFromHandler (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:512:31)\n at Promise._settlePromise (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:569:18)\n at Promise._settlePromise0 (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:614:10)\n at Promise._settlePromises (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:690:18)\n at _drainQueueStep (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\async.js:138:12)\n\nTypeError: Cannot read property ‘push’ of undefined\n at C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\gscan\lib\format.js:80:39\n at C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\lodash\lodash.js:4911:15\n at baseForOwn (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\lodash\lodash.js:2996:24)\n at C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\lodash\lodash.js:4880:18\n at Function.forEach (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\lodash\lodash.js:9344:14)\n at Object.format (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\gscan\lib\format.js:72:7)\n at resultHandler (C:\Workspace\NodeJS\ghost\versions\2.25.4\core\frontend\services\themes\validate.js:28:34)\n at tryCatcher (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\util.js:16:23)\n at Promise._settlePromiseFromHandler (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:512:31)\n at Promise._settlePromise (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:569:18)\n at Promise._settlePromise0 (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:614:10)\n at Promise._settlePromises (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\promise.js:694:18)\n at _drainQueueStep (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\async.js:138:12)\n at _drainQueue (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\async.js:131:9)\n at Async._drainQueues (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\async.js:147:5)\n at Immediate.Async.drainQueues (C:\Workspace\NodeJS\ghost\versions\2.25.4\node_modules\bluebird\js\release\async.js:17:14)\n at runCallback (timers.js:794:20)\n at tryOnImmediate (timers.js:752:5)\n at processImmediate [as _immediateCallback] (timers.js:729:5)”
},
“msg”: “Cannot read property ‘push’ of undefined”,
“time”: “2019-07-05T18:45:46.821Z”,
“v”: 0
}

You’re totally right this error message is horrible and shouldn’t be happening. Can you possibly share the theme that’s causing the error?

Hi Hannah,

thanks for getting back to me. I actually managed to solve this issue. For debugging I modified the core source code. This gave me the actual stack of errors.

I first had to fix the missing JS code for kg-gallery-image. I used the Casper code (Koenig gallery card support by kevinansfield · Pull Request #475 · TryGhost/Casper · GitHub)

Also, in my post.hbs I was using something like {{#if author.image}} which I initially changed to {{#ifprimary_author.profile_image}} - I was trying to check if there is a profile image for the user. But, this was incorrect also (and probably the cause for the vague error message. To fix it I changed it to {{#ifprimary_author}} check.

Those were the only changes I made and it works now.

My theme is called Spectre and I’m selling it through CreativeMarket: Spectre Ghost Theme Download

and you can see it working here: Spectre Ghost Theme Demo

By the way, I just want to say that you guys have done a really fantastic job with Ghost and would love to write another Ghost theme (or maybe an extension) soon

cheers,
John

1 Like