Is it possible to to load packages via npm for theme app extensions?

For an app we’re working, we’d like to be able to load an SDK via npm so that it can be used within a theme app extension. Is that possible? I know that it’s possible for web pixels, so here’s hoping.

Alternately, is it possible to do this directly in the liquid theme? I don’t see any promising candidates in the file listing, but maybe I’m missing something.

Thanks in advance!

Hey Raymond,

Do you have more details on the SDK and how you’re expecting to use it within a theme app extension? I know it’s (intentionally) not possible to load external JS libraries within a theme app extension, for performance reasons, so this limitation may be also blocking the SDK?

Hey Liam, thanks for the response.

The SDK is meant to send customer activity data to an external endpoint. There are other ways we can load it, such as through CDN, but in the past we have encountered issues when users have JS blockers running.

When you say it’s not possible load external libraries within the theme app extensions, does that include changes directly to the liquid theme code?

Hey Raymond - I’m not 100% sure I understand, theme app extensions would not be directly changing the code of themes, just creating a connection between the theme and the app. Maybe the scripttag API could be better to use: ScriptTag - GraphQL Admin

Will this be a custom app or a public app?

Hi Liam, it sounds like I should be more specific, because this is probably confusing without context.

Script tags are a valid solution, but the problem is that they are going away, so we need something a little more long term.

My understanding of theme app extension blocks is that they are essentially inserted into the UI code at the time of rendering. I’m also aware that one can directly edit files like theme.liquid to insert code that will run on the front end of the storefront. So I’m wondering if there’s a way to leverage npm within the theme code editor.

I’m guessing that the answer is no, because I’ve been looking through the editor for package.json or the equivalent, and I haven’t found anything. So I’m just asking in case I missed something.

Sorry, my use of Shopify platform terminology is probably a bit off, so this is probably more confusing than it needs to be. I appreciate any advice you have.

Hi again Raymond - it does sound like it won’t be possible to use npm in this context.