Upgrading `@builder.io/sdk` to 2.2.1 breaks build

Describe the bug
We’re trying to upgrade @builder.io/sdk to 2.2.1 from 2.1.1, it fails in build step:

throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));

The API key is defined as an environment variable and it is passed correctly. We even tried passing an API key directly to the builder.init() function, but it still didn’t work.

Additional context
It also appears that when we attempt to update @builder.io/react to 3.2.0 from 3.1.1, it fails with the same error.

Using:
Next.js 14.1
Node 18

Hello @neri!

Do you have the builder-registry.ts file in your project?

Same here and I have builder-registry.ts in my project

Hello @yannis,

You you try adding builder.init('API KEY') to the builder-registry.ts file and let us know how that works for you?

import { builder } from '@builder.io/react';

builder.init("YOUR API KEY or env variable");

Doesn’t work.

init doesn’t exist if I use:

import { Builder } from '@builder.io/react';
Builder.init(process.env.NEXT_PUBLIC_BUILDER_API_KEY!);

if I add

import { builder } from "@builder.io/sdk";
builder.init(process.env.NEXT_PUBLIC_BUILDER_API_KEY!);

I still have the same issue:

Builder integration error: Looks like the Builder SDK has not been initialized properly (your API key has not been set). Make sure you are calling builder.init("«YOUR-API-KEY»"); as early as possible in your application’s code.

It should be

import { builder } from ‘@builder.io/react’;
builder.init(process.env.NEXT_PUBLIC_BUILDER_API_KEY!);

Well it works but this seems a bit odd to have i think, maybe someone should work on the naming of the functions :stuck_out_tongue:

import { Builder, builder } from “@builder.io/react”;

Hello @yannis,

I’ll certainly raise a request for our team to further investigate and deploy a proper fix.

Thank you for bringing this to our attention,