React Script in Theme Extension onClick Reference Error

React Script in Theme Extension onClick Reference Error

ced1968
Shopify Partner
12 1 3

So I have a button that when pressed opens a modal window.  The script resides in the assets folder and it's ReactJS.  We get an error that we cannot use import outside a module so we used babel and compiled the file to bypass ES6.  When I swapped out the commonJS file, now I get the error that the modal is not defined.

 

the modalbutton.liquid file contains {{ 'iwtmodalbutton.js' | asset_url | script_tag: 'module' }} which exports the module.  

 

I have seen a few other articles in here around React and Shopify themes not playing nice in the sandbox.  Anyone have any thoughts?  Will a compiled file work or can we use ReactJS and maybe another plugin.

My sense is the modal window should be a global for the click handler to work. 

I used window reference to export the modal and no dice.   window.openOfferModal = openOfferModal;

 

I am sure there is something I am missing here.

 

 

Reply 1 (1)

ced1968
Shopify Partner
12 1 3

This is the error.  I have heard there are issues at times with ReactJS in Shopify theme extensions.  Any insights would be helpful.

Screen Shot 2024-05-30 at 9.14.23 AM.png