Buy Me a Coffee

[DecapCMS/NetlifyCMS] Invalid String Length Error

The Problem

While using DecapCMS in a local environment, you might encounter the following error:

error: Error handling {"branch":"feat/add-new-post","action":"getMedia","params":{"branch":"feat/add-new-post","mediaFolder":"static/images"}}: Invalid string length 

Context: The repository is built with Hugo. It is approximately 600MB, with a static/images folder containing about 5000 images totaling more than 500MB.

This error doesn’t appear when DecapCMS is run on a production environment like Netlify, but locally it occurs when attempting to view certain pages.

Running DecapCMS Locally

To run DecapCMS locally, you use:

npx decap-server

The Solution

To address the error, modify the config.yml file for DecapCMS. Here’s an example of a typical configuration:

 1media_folder: static/images
 2public_folder: /images
 3logo_url: /favicons/apple-touch-icon.png
 4display_url: 'https://example.netlify.app'
 5show_preview_links: true
 6search: true
 7slug:
 8  encoding: ascii
 9  clean_accents: true
10  sanitize_replacement: '-'
11backend:
12  name: github
13  branch: main
14  repo: repo/example
15collections:
16...

Step-by-Step Fix

When debugging locally, displaying all images is often unnecessary. The focus is typically on viewing content. Hence, we can reduce the image load by:

  1. Create a Simple Folder: Make a new folder static/images/cms-uploads containing just a couple of images.

  2. Modify config.yml:

Update the settings as follows:

 1media_folder: static/images/cms-uploads
 2public_folder: /images/cms-uploads
 3logo_url: /favicons/apple-touch-icon.png
 4display_url: 'https://example.netlify.app'
 5show_preview_links: true
 6search: true
 7slug:
 8  encoding: ascii
 9  clean_accents: true
10  sanitize_replacement: '-'
11backend:
12  name: github
13  branch: main
14  repo: repo/example
15collections:
16...
  1. Restart the Server: Restart the DecapCMS server to apply the changes.

After adjusting the configuration, you should be able to access the problematic pages without encountering the “Invalid string length” error.

By streamlining the image files accessed by DecapCMS locally, this fix simplifies debugging and content checking without hindrance from large image datasets.


Enjoyed this article? Support my work with a coffee ☕ on Ko-fi.
Buy Me a Coffee at ko-fi.com
DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !