Remix template console.log not working

HelpDigital
Shopify Partner
8 0 1

Hi

 

I'm a Remix newbie, trying to modify a copy of the remix template code to achieve what I need. I'm trying to use form values in my Mutation  / function code.

However, the console.log feature won't output when the rest of the function runs - which makes debugging and learning what is happening really difficult.

 

Can someone explain why the console log doesn't work when used within in this function? (it doesn't work on the default template app._index.jsx either)

and ideally, give me a pointer as to how I can use a form (text input field) value in my graphql code. 

My action function and mutation works as expected with hardcoded values. 

 

Thanks.

 

 

 export const action = async ({ request }) => {
   const { admin } = await authenticate.admin(request);
   const formData = await request.formData();
   console.log("Action is called"); // WHY DOESN'T THIS LOG ANYTHING TO THE CONSOLE???
   const response = await admin.graphql(
     `#graphql
    mutation draftOrderUpdate($id: ID!, $input: DraftOrderInput!) {
      draftOrderUpdate(id: $id, input: $input) {
        draftOrder {
          id
          customAttributes {
            key
            value
          }
        }
        userErrors {
          field
          message
        }
      }
    }`,
    
    {
      variables: {
      id: `gid://shopify/DraftOrder/905513205805`,
      input:{
         customAttributes: {
           key: "Gift message",
           value: "test" // I'M TRYING TO MAKE THIS VALUE DYNAMIC FROM A FORM INPUT ???
        }
      }
    } 
    }
        );
    
        const responseJson = await response.json();
  
    return json({
      draftOrder: responseJson.data.draftOrderUpdate.draftOrder
     });
  }

 

 

Replies 7 (7)

Liam
Shopify Staff
2731 294 744

Hi HelpDigital,

 

In Remix, functions like action run on the server-side and not in the browser. This means that console.log statements inside these functions will log to the server console, not the browser console. If you're running your server locally, you should be able to see the logged output in the terminal where you started your server.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

HelpDigital
Shopify Partner
8 0 1

Thanks Liam, 

 

They don't show in the command line console either -  I can see the Post requests and console.log output from other functions, but just not the ones in loader or action functions.  Is there any other way to output values passed in via the form?

 

Thanks,

Leo

CuriousDevelop
Shopify Partner
1 0 0

Hi HelpDigital

I have a similar problem, that i cant find anywhere (browser or terminal in vs code) where console.log displays.
My code is the following

 const [isDeleting, setIsDeleting] = useState(false);
  const deleteQRCode = useCallback(async () => {
    reset();
    /* The isDeleting state disables the download button and the delete QR code button to show the merchant that an action is in progress */
    setIsDeleting(true);

   
    console.log("its starting");

i simply added a console.log statement to deleteQRCode function.
Did you find a solution?

techticarti1
Shopify Partner
1 0 0

Hii @HelpDigital , I am having same issue, so did you found any solution for it?. If so then please let me know.

ronnycoding
Shopify Partner
5 0 1

you should be able to set you logger through the shopify app initialization

 

const shopify = shopifyApp({
...mySettings,
logger: {
    level: process.env.VERCEL_ENV ? LogSeverity.Info : LogSeverity.Debug,
    log: (level, message) => {
      // Log to your logging service
    },
    timestamps: true,
    httpRequests: true,
  },
})

// export logger
export const logger = shopify.logger

//and import the logger

logger.log(LogSeverity.Debug, { topic, shop, payload });

 

ronnycoding
Shopify Partner
5 0 1

actually I'm wrong, about exporting the logger, this is not exported from shopifyApp

ronnycoding
Shopify Partner
5 0 1

inspired for what I said before this is a change you can do in a fork of this shopify-app-remix where I exposed the shopify logger and use it as I want to

 

logger.log(LogSeverity.Info, "App test log -------->");

 



Screenshot 2024-02-24 at 10.54.47.png
if you want to use it, you can install

add the following script to your package.json
```

"link-package": "[ -d ./node_modules/@ronnyf89/shopify-app-remix ] && ln -sf ../@ronnyf89/shopify-app-remix ./node_modules/@shopify/shopify-app-remix",
```

and then run pnpm add 
@ronnyf89/shopify-app-remix