Skip to content
Advertisement

Debugging Sanity exec with VS Code

I’m using Sanity (sanity.io headless CMS) and doing some data migration with the CLI.

How do I (or, is it at all possible) to some how attach the vscode debugger and stop at breakpoints in migration scripts. I’m running the following cli migration script: sanity exec migrate.js --with-user-token. I would like to stop at breakpoints in migrate.js?

I’ve managed debugging console apps run with node but don’t know if it is possible to get the debugger to engage when starting the script with sanity exec ... Stepping through the code is such a great way to find bugs and learn.

Advertisement

Answer

I was ultimately unsuccessful with debugging the sanity exec command, but after reworking the script I got most of the same stuff done with normal node debugging.

  • I import-ed client from '@sanity/client'.
  • Made access-tokens to the projects I wished to write to or read drafts from.
  • Added appropriate launch-config and,
  • Ran the node v14.2.0 normal debugger from vscode and step through my script with breakpoints.
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement