Home App Docs Blog Github

registerDataPlugin causes cannot read properties of undefined (reading 'organization') error

What are you trying to accomplish
I want to explore developing a data plugin

Screenshots or video link

Code stack you are integrating Builder with
NextJS

Reproducible code example

import { registerDataPlugin } from '@builder.io/data-plugin-tools';

registerDataPlugin({
    id: "@example/plugin-dummy",
    name: "lollenplugindummy",
    settings: [],
    ctaText: `plugin-dummy to test out functionality`,
    getResourceTypes: async () => {
        return [{
            id: "alldogs",
            name: "All dogs",
            description: "Get a list of all dog breeds",
            toUrl: (options: any) => {
                return "https://dog.ceo/api/breeds/list/all"
            },
            canPickEntries: true,
            inputs: () => []
        }]
    },
})

The above code when run throw a Cannot read properties of undefined (reading ‘organization’) error.

Suspecting the errors are from the rows referencing appState.user.organization (appState.user being undefined) in builder/index.ts at 395b715bf359b086a8d287b6be5aa172303bdd20 · BuilderIO/builder · GitHub

I therefore tried to import appState from @builder.io/app-context but it only gives me an empty object (which might explain the above error cause)

I have not been able to find any documentation to work around this issue other than possibly the license levels describing private plugins requiring enterprise license.

Worth mentioning, registering custom components and testing it out trough builder.io page builder works excellent, so the code is initialized correctly i believe.

Anyone got any advice?

Cheers!

Hi @lollen , looking at the interface I think you’re using an outdated version of @builder.io/data-plugin-tools module, but don’t think it’s related to the error you’re seeing, I think the error has something to do with webpack not playing well with one of our externals, I went ahead and released the latest code to npm and added an example that uses rollup with sample code and instructions that should help you with a starting point on how to add data plugins to builder, you can find it here , for an example of a data plugin that we current use in production check our contentful data plugin source code