Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to debug in visual studio code when running a backend shopify app?

Solved

How to debug in visual studio code when running a backend shopify app?

zhicheng1
Shopify Partner
28 2 10

I'm making a sales channel app which requires running a backend server.  Is there anyway to debug this app while I am running locally?  The problem is the app is launched from shopify.exe and even though it runs nodejs somewhere down the line, visual studio seems unable to debug with it.  Is there anything that can be done?

Accepted Solution (1)

zhicheng1
Shopify Partner
28 2 10

This is an accepted solution.

Hey I managed to do it and it was easy.  Just go to run->add configuration and then add a "node" configuration.

View solution in original post

Replies 11 (11)

zhicheng1
Shopify Partner
28 2 10

This is an accepted solution.

Hey I managed to do it and it was easy.  Just go to run->add configuration and then add a "node" configuration.

Liam
Community Manager
3108 344 902

Glad you figured this out Zhicheng1 - thanks for coming back to update this post 🙂 

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

GeorgeHoffman
Shopify Partner
28 0 5

can you put any more details?

ShopifyDevSup
Shopify Staff
1453 238 530

Hey @GeorgeHoffman

 

Are there any additional details you're specifically looking for? 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

GeorgeHoffman
Shopify Partner
28 0 5
The accepted answer might work but its vague and I'm not sure how to implement it. What does it mean to add a node configuration. An example configuration would be very helpful. I tried several things to debug local plugins and fear the issue is maybe it transpiles to WASM which I don't think VS code understands. When I set breakpoints in the source code it says the breakpoint is not connected and never triggers. The WASM output is binary and not possible to set a breakpoint. Or maybe there is some way to add a source map similar to how compiled javascript works. A clear example or documentation would be amazing on how to debug checkout functions. When working with the new plugins we have to rely on the partner console output but what happens if your method is not firing at all so there is no output.

k1ltr0
Shopify Partner
10 0 0

I just did click on show al configurations and then selected the dev script from package.json

 

k1ltr0_0-1720469705402.png

k1ltr0_1-1720469792800.png

This will open a terminal with command and debugger attached

k1ltr0_2-1720469853793.png

 

 

Hi, I’m Ric from Codename.cl. I develop Shopify apps like Ship Smart (custom shipping rates) and Product Sentinel (pricing alerts). Open to new projects & collaborations!

Hola, soy Ric de Codename.cl. Desarrollo aplicaciones de Shopify como Ship Smart (custom shipping rates) y Product Sentinel (pricing alerts). Estoy abierto a nuevos proyectos y colaboraciones!
GeorgeHoffman
Shopify Partner
28 0 5
It's something I had tried. I don't see any breakpoints getting hit no matter what I do which is why I asked. Maybe it only works in certain version of VS code or maybe there was some change on the Shopify side. I moved on to other projects so maybe will try again someday.
tomcomtech
Shopify Partner
1 0 0

I also can't hit any breakpoints. Anyone any ideas? 

egdevelopment
Shopify Partner
1 0 0

Here are the steps that worked for us:

 

1. In VS Code, hit F1 and type add Configuration and choose the option Debug: Add Configuration to open the launch.json file.egdevelopment_1-1725542443253.png

 

2. In the launch.json file, add this in your configurations array. You might want to tweak it depending on your package manager and folder structure (this is working with yarn and the package.json at the root of our workspace folder). The "yarn dev" script looks like this in our package.json file "dev": "shopify app dev"

 

{
      "type": "node-terminal",
      "request": "launch",
      "name": "Debug Shopify App",
      "command": "yarn dev",
      "cwd": "${workspaceFolder}"
    }

3. Click on the Debug icon in VSCode, then select your newly added configuration and hit play. It will start your debug session and you will be able to hit breakpoints

 

egdevelopment_3-1725542926453.png

 


 
sauzer77
Shopify Partner
5 0 2

I tried this, but when I try to select a breakpoint it, says that it's unbound.

I followed the instructions, but my "command "is not `yarn dev`, but it's `shopify theme dev`.

Maybe there is another setup I need to do to my environment to make it work with yarn or npm?

sauzer77_0-1726560869985.png

 

k1ltr0
Shopify Partner
10 0 0

I think breakpoints doesn't work in code running in front end, just in the code running in backend like loader or action functions. you may try writting a line witgh the word debugger and open the developer console in the web browser to check if the code stops there.

k1ltr0_0-1727115627392.png

 

Hi, I’m Ric from Codename.cl. I develop Shopify apps like Ship Smart (custom shipping rates) and Product Sentinel (pricing alerts). Open to new projects & collaborations!

Hola, soy Ric de Codename.cl. Desarrollo aplicaciones de Shopify como Ship Smart (custom shipping rates) y Product Sentinel (pricing alerts). Estoy abierto a nuevos proyectos y colaboraciones!