Ghost: Update to 0.10.1 fails when using Ghost as an npm module (TypeError: _.toPairs)

Created on 7 Sep 2016  Â·  21Comments  Â·  Source: TryGhost/Ghost

Issue Summary

2016-09-07T08:19:09.627945+00:00 app[web.1]: Migrations: Creating database backup
2016-09-07T08:19:09.687236+00:00 app[web.1]: 
2016-09-07T08:19:09.687239+00:00 app[web.1]: ERROR: undefined is not a function 
2016-09-07T08:19:09.687260+00:00 app[web.1]:     at getSettingsResult (/app/node_modules/ghost/core/server/api/settings.js:357:44)
2016-09-07T08:19:09.687281+00:00 app[web.1]:     at tryCatcher (/app/node_modules/ghost/node_modules/bluebird/js/release/util.js:16:23)
2016-09-07T08:19:09.687290+00:00 app[web.1]:     at Promise._settlePromise (/app/node_modules/ghost/node_modules/bluebird/js/release/promise.js:561:18)
2016-09-07T08:19:09.687290+00:00 app[web.1]:     at Promise._settlePromise0 (/app/node_modules/ghost/node_modules/bluebird/js/release/promise.js:606:10)
2016-09-07T08:19:09.687290+00:00 app[web.1]:     at Promise._settlePromises (/app/node_modules/ghost/node_modules/bluebird/js/release/promise.js:685:18)
2016-09-07T08:19:09.687291+00:00 app[web.1]:     at Async._drainQueue (/app/node_modules/ghost/node_modules/bluebird/js/release/async.js:138:16)
2016-09-07T08:19:09.756832+00:00 app[web.1]:     at Async._drainQueue (/app/node_modules/ghost/node_modules/bluebird/js/release/async.js:143:12)
2016-09-07T08:19:09.756834+00:00 app[web.1]:     at Immediate.Async.drainQueues (/app/node_modules/ghost/node_modules/bluebird/js/release/async.js:17:14)
2016-09-07T08:19:09.756837+00:00 app[web.1]:     at Immediate._onImmediate (/app/node_modules/@risingstack/trace/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)
2016-09-07T08:19:09.757542+00:00 app[web.1]:     at Promise._settlePromise (/app/node_modules/ghost/node_modules/bluebird/js/release/promise.js:561:18)
2016-09-07T08:19:09.757542+00:00 app[web.1]:     at Promise._settlePromiseCtx (/app/node_modules/ghost/node_modules/bluebird/js/release/promise.js:598:10)
2016-09-07T08:19:09.757544+00:00 app[web.1]:     at Immediate.Async.drainQueues (/app/node_modules/ghost/node_modules/bluebird/js/release/async.js:17:14)

Steps to Reproduce

  1. Update to [email protected]

    Technical details:

  • Ghost Version: 0.10.1
  • Node Version: 4.x
  • Browser/OS: Alpine
  • Database: Postgre
bug help wanted

Most helpful comment

The correct workaround would be to require the overrides file inside of your version of the index.jsfile. I realise it is not ideal, but it should solve your problem without waiting for another release.

All 21 comments

Consider this:

> _.toPairs = toPairs
[Function]
> _.toPairs
undefined
> Object.isFrozen(_)
true
> Object.isExtensible(_)
false

simply this commit (https://github.com/TryGhost/Ghost/commit/54559f24f95239740b8f988d48a08ea276f7b335) has no effect on the lodash object

@kirrg001 @ErisDS please take a look at this

Also, I would warn users not to update

Hey there @gergelyke, I'm not sure what has happened for you here. We have successfully upgraded all of our production blogs on Ghost(Pro) so I'm 100% confident that the upgrade does work.

Without some more info about your specific environment, I'm not sure what to suggest other than to read through the upgrade troubleshooting guide, check everything over and if you're still having trouble swing by the #help channel in our slack team.

Going to close this because, as I said I'm confident the upgrade works. Feel free to post back if you find something specific that does identify this as a bug rather than and environment / upgrade issue and I'll reopen.

@ErisDS any chance that you still have [email protected] installed on those machines?

Also, if you try running that codesnippet you will see that this solution simply does not work

@jdalton could you help us out here?

@gergelyke I understand what you're getting at, but I, having upgraded literally 10s of 1000s of blogs, have not been able to reproduce the error you are seeing.

Please can you provide the exact details of how you upgraded? What version were you on before? Which method did you use? What commands exactly did you run?

Are you sure you don't have lodash@4 on those systems?

We were on 0.9 before, and upgraded to 0.10.1 - simply updated in the package.json, ran npm install, and that's it. Well, to be more precise:

FROM risingstack/alpine:3.4-v4.4.7-3.6.2

EXPOSE 2368

COPY package.json package.json
RUN npm install
RUN mkdir /var/node-app

# Add your source files
COPY . .
CMD ["npm", "start"]

this is the Dockerfile we are using

Are you sure you don't have lodash@4 on those systems?

100% we use the zip file & the containers are completely replaced with a
new version. Therefore the dependencies match exactly what is in the
npm-shrinkwrap.json file provided in the prebuilt zip.

Is your node_modules folder getting removed and rebuilt fresh?

On 7 September 2016 at 13:48:40, Gergely Nemeth ([email protected])
wrote:

Are you sure you don't have lodash@4 on those systems?

We were on 0.9 before, and upgraded to 0.10.1 - simply updated in the
package.json, ran npm install, and that's it. Well, to be more precise:

FROM risingstack/alpine:3.4-v4.4.7-3.6.2

EXPOSE 2368

COPY package.json package.json
RUN npm install
RUN mkdir /var/node-app

Add your source files

COPY . .
CMD ["npm", "start"]

this is the Dockerfile we are using

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/TryGhost/Ghost/issues/7336#issuecomment-245256206,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGMiTwz-dK3ZCGOloRPmpUnRRFq6Rt7ks5qnqSYgaJpZM4J2p68
.

Yes, they are

The Lodash function, _, isn't frozen by default and using _.mixin shouldn't help with that.
The _.mixin method will make those others available for chaining though, e.g. _(obj).toPairs().map(...).value()

I'm having a very similar issue.

I've setup Ghost for my new blog. I use it as a NPM Module.

I recently updated the blog from 0.7 to 0.8 then 0.9 with no issue.

But when I updated Ghost to the latest version (0.10.1) I got an error error:

Unhandled rejection TypeError: _.toPairs is not a function
    at settingsFilter (/www/al-blog/node_modules/ghost/core/server/api/settings.js:112:35)
    at settingsResult (/www/al-blog/node_modules/ghost/core/server/api/settings.js:215:37)
    at /www/al-blog/node_modules/ghost/core/server/api/settings.js:361:28
    at tryCatcher (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/promise.js:504:31)
    at Promise._settlePromise (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/promise.js:561:18)
    at Promise._settlePromiseCtx (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/promise.js:598:10)
    at Async._drainQueue (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/async.js:143:12)
    at Async._drainQueues (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/www/al-blog/node_modules/ghost/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
Ghost has shut down

Your blog is now offline
Migrations: Creating database backup
Migrations: Database backup written to: /www/al-blog/content/data/ghost.2016-09-07.json
Migrations: Migration required from 006 to 007
Migrations: No tasks found for version
Migrations: Updating database to 007
Migrations: Running fixture updates
Skipping Migrations: rolling back because of: undefined
Ghost is running in production…

Spec:

Ghost Version: 0.7.8
Node Version: v4.4.2
NPM Version: 3.8.5
Browser/OS: All
Database: MySql

@ErisDS okay, I found the issue

The problem is the following: the overrides.js file is required in /index.js, and I use ghost as a required npm module. As per the package.json's main property is ./core/index, the overrides are simply not used.

Is it by design? How should we fix this?

PS: for now I have no idea why my terminal showed me that the lodash object is frozen, going to investigate that as well

This PR solves it: https://github.com/TryGhost/Ghost/pull/7339
However, I am not sure this is the best way to do it - it would be better to include it in only of the files (core/index), however I am not sure whether the core/server/utils/startup-check depends on it or not

Please let me know what do you prefer, and release this fix asap, we cannot upgrade ghost, and the memory leak is killing us

The correct workaround would be to require the overrides file inside of your version of the index.jsfile. I realise it is not ideal, but it should solve your problem without waiting for another release.

@ErisDS that's a good idea, thanks! What should be the long-term solution? I am happy to contribute that

I also had this issue when running Ghost as a npm module, but adding

require('ghost/core/server/overrides');

to the beginning of my server.js solved it. Thank you!

@gergelyke I think the correct fix would be to either move or duplicate the inclusion of the overrides file as the very first line in /core/index.js.

It would need a bit of testing and checking to see what the impact is if you do not include the file in your own index.js/server.js and it would be ideal if someone who uses ghost this way could do that.

The most important line in the overrides file is actually:

moment.tz.setDefault('UTC');

As that ensures that dates are handled for you.

Was this page helpful?
0 / 5 - 0 ratings