Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] describe console logging of the build process #18816

Merged
merged 3 commits into from
Oct 29, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/docs/debugging-the-build-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Gatsby's `build` and `develop` steps run as a Node.js application which you can

In this guide you will learn how to debug some code using:

- [Debugging with Node.js' built-in console](#debugging-with-nodejs-built-in-console)
kriswep marked this conversation as resolved.
Show resolved Hide resolved
- [VS Code debugger (Auto-Config)](#vs-code-debugger-auto-config)
- [VS Code debugger (Manual-Config)](#vs-code-debugger-manual-config)
- [Chrome DevTools for Node](#chrome-devtools-for-node)
Expand Down Expand Up @@ -40,6 +41,33 @@ TypeError: Cannot read property 'internal' of undefined
D:/dev/blog-v2/gatsby-node.js:6:12
```

## Debugging with Node.js' built-in console

One of the fastest ways to gain insight into Gatsby's build process is using the `console` functionality [built into Node.js](https://nodejs.org/en/knowledge/getting-started/the-console-module/). This works similar to how you might be used to in the browser.

Adding a console.log statement in our sample from above will print the variable into your terminal. There you might notice that `args` contains a lower-cased node variable.
kriswep marked this conversation as resolved.
Show resolved Hide resolved

```diff:title=gatsby-node.js
const { createFilePath } = require("gatsby-source-filesystem")

exports.onCreateNode = args => {
+ console.log(args)
muescha marked this conversation as resolved.
Show resolved Hide resolved
const { actions, Node } = args
if (Node.internal.type === "MarkdownRemark") {
const { createNodeField } = actions

const value = createFilePath({ node, getNode })
createNodeField({
name: `slug`,
node,
value,
})
}
}
```

For a refresher what is part of the build process check out the differences between [build and runtime](/docs/overview-of-the-gatsby-build-process#build-time-vs-runtime). Generally spoken, Node.js is responsible for building Gatsby pages and therefore its' built-in objects like `console` can be used.
kriswep marked this conversation as resolved.
Show resolved Hide resolved

## VS Code Debugger (Auto-Config)

If you use VS Code and its integrated terminal, you can configure it to automatically create the debug config for you.
Expand Down