Craft is not defined

When I dev on localhost, everything is fine.

When I compress a .craftx file, open it on craft, show me a white screen.

So I open the index.html, console tell me “craft is not defined”

Have no idea what happen, and can’t debug in craft.

craft-extension-project-templates/typescript-react at master · craftdocs/craft-extension-project-templates · GitHub

I use above template make my extension. and I don’t known how the craft global variable be injected.

craft-extension-api-sdk/index.ts at master · craftdocs/craft-extension-api-sdk · GitHub

looks like only injected in dev mode?

Hi, the craft object should be inject by the app automatically. If other extensions work well for you, then I think your extension might be calling the craft object too early, before its properly injected.

Could you please try removing the craft object from the initializer code thats immediately running in your extension and see if it works well, when you put the code to an event handler, for example when you click on a button (like in the template).

Yes, I solve this issue.

Because I use craft.storageApi at Recoil.Atom.default

The question is how early is early? why my code run before injected?

We also managed to reproduce this issue on our side and will create a fix, so extensions won’t need to deal with this problem. For the time being please try to work around this limitation by adding a delay before you use the object (indeed the timing is not deterministic, so you might need to check if the object is available after the wait).