Old StackBit Repo to Netlify Visual Editor - compliant stackbit.config.ts ?!

Our very old website:

iaeste-hh-ee1a7.stackbit.app, built on Node 14 something using the olde Stackbit Editor.

We want to transition into the new visual editor.

A) there should be lots of sites that were barebone stackbit pages. Is there a guide somewhere made for those kinds of sites?

From what Iunderstand, the steps should be:

  1. make sure you own the repo on your giothub (we do)
  2. make sure a stackbit.config.ts exists (we created one, using the minimal configuration
  3. Configure your content model correctly

B) are there any example files made for/from any of the old StackBit Templates?
It would be mighty helpful if I could see what I need to change based on a similar example.

To fulfill Step 3, I understand I need to itreate through the entire folder /project_root/content/pages , mentally parse every page’s content model and type that up in some custom .ts structured language?

Since I am not sure and manually iterating over files is a big time investment, I wanted to make sure this is going the right way. Here is my current best guess based on one page:

import { GitContentSource } from "@stackbit/cms-git";

export default {
  stackbitVersion: '~0.6.0',
  ssgName: 'nextjs',
  nodeVersion: '14',
  models: {
    Page: {
      fields: [
        { name: 'title', type: 'string', required: true },
      ],
    },
  },
}

I am not sure what my next step should be in order to iterate further until my stackbit.config.js is compliant.

The most recent reload of teh Visual Editor after the above changes returns this funny CTA:

image

Hi there! It looks like your project iaeste-hh-ee1a7.stackbit.app is using the deprecated stackbit.yaml format. At this point, this format is no longer supported. In order to proceed with enabling the visual editor, you’ll need to ensure you’re using the correct stackbit.config.ts file (which is sounds like you’ve created).

are there any example files made for/from any of the old StackBit Templates?

You can deploy the visual editor from any of the following templates:
Next.js + MUI Starter
Astro + Sanity Starter
Portfolio site with visual editing
Next.js + Contentful Minimal Starter
Content Ops Starter

These can be found by navigating to your sites > Add new site > Start from template.

If you’re using Next.js, you can reference this documentation for an example and walkthrough of what that configuration requires:

Additionally, our content sources documentation walks through the configuration depending on what content source you’re using:

1 Like

See, that is the point I got stuck on.

Attempts of fixing stackboit.config.ts

I thought of doing it the way you describe myself. But I have not found any combination of entries in stackbit.config.ts that would let the Visual editor even fucking load. It is stuck in booting mode since June with the following minimalist .ts:

stackbit.configs.ts v1
export default {
  stackbitVersion: '~0.6.0',
  ssgName: 'nextjs'
}

NOT WORKING

All I need is the content to sit in plaintext files inside the same repo. I have deployed, like you suggested, a new version based on the same old template from scratch to go and steal the stackbit.config.js but this is fruitless since the folder structures are completely different in terms of where content is stored and how it is split up (aka content model).

Then I tried

stackbit.configs.ts v2
import { defineStackbitConfig, DocumentStringLikeFieldNonLocalized, SiteMapEntry } from '@stackbit/types';
import { GitContentSource } from '@stackbit/cms-git';
import { allModels } from 'sources/local/models';

export default {
  stackbitVersion: '~0.6.0',
  ssgName: 'nextjs'
}

NOT WORKING

and finally I tried

stackbit.configs.ts v3
import { defineStackbitConfig, DocumentStringLikeFieldNonLocalized, SiteMapEntry } from '@stackbit/types';
import { GitContentSource } from '@stackbit/cms-git';
import { allModels } from 'sources/local/models';

const gitContentSource = new GitContentSource({
    rootPath: __dirname,
    contentDirs: ['content'],
    models: Object.values(allModels),
    assetsConfig: {
        referenceType: 'static',
        staticDir: 'public',
        uploadDir: 'images',
        publicPath: '/'
    }
});

export const config = defineStackbitConfig({
    stackbitVersion: '~0.6.0',
    ssgName: 'nextjs',
    nodeVersion: '18',
    styleObjectModelName: 'ThemeStyle',
    contentSources: [gitContentSource],
    presetSource: {
        type: 'files',
        presetDirs: ['sources/local/presets']
    },
    siteMap: ({ documents, models }): SiteMapEntry[] => {
        const pageModels = models.filter((model) => model.type === 'page').map((model) => model.name);
        return documents
            .filter((document) => pageModels.includes(document.modelName))
            .map((document) => {
                let slug = (document.fields.slug as DocumentStringLikeFieldNonLocalized)?.value;
                if (!slug) return null;
                /* Remove the leading slash in order to generate correct urlPath
                regardless of whether the slug is '/', 'slug' or '/slug' */
                slug = slug.replace(/^\/+/, '');
                switch (document.modelName) {
                    case 'PostFeedLayout':
                        return {
                            urlPath: '/blog',
                            document: document
                        };
                    case 'PostLayout':
                        return {
                            urlPath: `/blog/${slug}`,
                            document: document
                        };
                    default:
                        return {
                            urlPath: `/${slug}`,
                            document: document
                        };
                }
            });
    }
});

export default config;

NOT WORKING

Current “Progress”

Well, I keep getting an annoying lodash error (see below) no matter what I do to the stackbit file.

lodash Error
### Diagnosis

The build failed at the `npm run build` stage with a `Type error: '?' expected` in the file `node_modules/@types/lodash/common/object.d.ts` at line [293](https://app.netlify.com/sites/iaeste-hh-ee1a7/deploys/66a6489e57cdf10008706edd#L293).

### Solution

This error is likely due to a TypeScript error in the `@types/lodash` definition file. To resolve this issue, you can try the following steps:

* Update your dependencies to ensure you have the latest version of `@types/lodash`.
* If updating doesn't resolve the error, you may need to check your code for any issues that could be causing this TypeScript error, such as incorrect type usage or undefined checks.

Additionally, you should consider checking for any compatibility issues between the version of `@types/lodash` and other dependencies in your project.

At this point I am questioning whether there is any point to continuing to use the current repository. Even without the visual editor the repository doesn’t build any more, thus it seems to be most reasonable to rebuild from scratch using the visual editor.

I am a bit flabbergasted about the transition documentation being so … empty. There is a lot of boilerplate content in the docs but nothing that specifically speaks to “How to convert your config files/repos so that they are compatible witht he new visual editor build environment”.

At this point, since the .yaml project format was deprecated so long ago, there’s no way to migrate that project to the new format. Since this project hasn’t worked on the old Stackbit app for some time, it will no longer work with the visual editor either. The best way to move forward is to refer to our documentation on getting started and creating a new config file.

It does look like you’ve successfully enabled visual editing on a different site, which is great news! If you run into issues starting this specific project over, feel free to follow up in this thread with details and we can go from there.

Well, not really. Setting up a new config.ts is not helpful as it still breaks the build. As I cannot infer the infromation needed from the folder structures nor the existing deprecated config files I see no other option forward except using the same tempalte we started with 2 or 3 years ago and redevelop from scratch.

If you’re seeing failed builds and would like assistance troubleshooting those, feel free to link us to the failed build in question or provide the build logs here for further assistance