Solved

Unexpected Server Error Error: shopify.toast can't be used in a server environment.

rahular
Shopify Partner
5 1 3

I am trying the shopify remix app tutorial for embedded apps but I am getting an error

Unexpected Server Error

Error: shopify.toast can't be used in a server environment. You likely need to move this code into an Effect.

 

I haven't done any coding I just did init and then npm run dev

Accepted Solution (1)

rahular
Shopify Partner
5 1 3

This is an accepted solution.

All those who are facing this issue comment

// useEffect(() => {
// if (productId) {
// // shopify.toast.show("Product created");
// }
// }, [productId, shopify.toast]);
in app._index.jsx in routes
It started working

View solution in original post

Replies 9 (9)

doctor3d
Shopify Partner
1 0 2

same issue here . brand new embedded app - 

doctor3d_0-1711204201649.png

 

skorp
Shopify Partner
2 0 1

same here

Trendscopes
Shopify Partner
2 0 2

same problem

sergioserrenho
Shopify Partner
1 0 1

Same problem here

z_solutions
Shopify Partner
2 0 1

z_solutions_0-1711302583286.png

in app/routes/app._index.jsx or tsx 

DigitalSpaces
Shopify Partner
1 0 0

Commenting out that line doesn't work for me.  Even after I killed and re-ran my dev server.

 

edit: comment out the entire useEffect hook and it should run.

rahular
Shopify Partner
5 1 3

This is an accepted solution.

All those who are facing this issue comment

// useEffect(() => {
// if (productId) {
// // shopify.toast.show("Product created");
// }
// }, [productId, shopify.toast]);
in app._index.jsx in routes
It started working
Pabloo
Shopify Partner
2 0 0

Commenting out the code as a temporary workaround. However, this doesn't address the root cause and simply postpones the problem. 

It appears that the useEffect hook itself might not be triggering correctly on mobile devices. Updating state variables from within the useEffect does not work.

 

rahular
Shopify Partner
5 1 3

The toast is not imported properly no issue with hooks since it's boilerplate I think shopify would fix it in next update