Error enabling persistent context

I'm running NR v0.20.6, Node.js v8.11.2 and trying to enable persistent context storage. In my settings.js file,

contextStorage: {
    default: {
        module:"memory"
    },
}

works fine, but

contextStorage: {
    default: {
        module:"localfilesystem"
    },
}

produces this:

[error] Failed to start server:
[error] Error: Error loading context store: SyntaxError: Unexpected token u in JSON at position 0
at /usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/context/index.js:177:15
at <anonymous>

If this isn't a bug, where should I be looking for my mistake?

My guess is that you have a corrupted context store file. Whether node-red should fail to start in that case I don't know.
If you have a look at https://nodered.org/docs/api/context/store/localfilesystem it shows you where the context files are stored. If you don't have anything that you need already in the context then if you rename the context folder and start node red then I expect it will recreate it for you. Rename rather than delete, for the moment, in case one of the experts wants to have a look at the contents.

1 Like

Well from all that is pasted above there is no config for the localfilesystem so that needs to be defined.

(Yes the error message could be more helpful :slight_smile:

That seems to be it. Renamed the context folder, and all seems well. No time to look for the culprit, but I saved the old folder and have a candidate in mind. Thanks! :grinning:

Not sure what you mean here. When I followed @Colin's advice, NR re-created the files for everything in the flow that used persistent context. It could be better for NR to fall back on memory-only context storage and post a warning in the editor. I might have sorted it eventually on my own, but I really wasn't sure how to proceed.

Sorry - in the snippet you posted there was no config object to specify the directory so I assumed you had omitted to define it.

Got it. Bigger snippets next time.

In fact, you were right. I used the contextStorage property exactly as it is in the settings.js file on GitHub -- no config object at all. I assumed I would get the defaults. Is that asking for trouble?