---
title: Debugging
description: How can I debug my styles or profile the extraction process?
---

## bamboo debug

Bamboo's built-in debug command helps you see which files are processed, what styles are generated, and your final
config.

By default it will scan and output debug files for the entire project depending on your `include` and `exclude` options
from your config file.

<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
  {/* <!-- prettier-ignore-start --> */}
  <Tab>
    ```bash
    pnpm bamboo debug
    # You can also debug a specific file or folder
    # using the optional glob argument
    pnpm bamboo debug src/components/Button.tsx
    pnpm bamboo debug "./src/components/**"
    ```
  </Tab>
  <Tab>
    ```bash
    npx bamboo debug
    # # You can also debug a specific file or folder
    # using the optional glob argument
    npx bamboo debug src/components/Button.tsx
    npx bamboo debug "./src/components/**"
    ```
  </Tab>
  <Tab>
    ```bash
    yarn bamboo debug
    # # You can also debug a specific file or folder
    # using the optional glob argument
    yarn bamboo debug src/components/Button.tsx
    yarn bamboo debug "./src/components/**"
    ```
  </Tab>
  <Tab>
    ```bash
    bun bamboo debug
    # # You can also debug a specific file or folder
    # using the optional glob argument
    bun bamboo debug src/components/Button.tsx
    bun bamboo debug "./src/components/**"
    ```
  </Tab>
  {/* <!-- prettier-ignore-end --> */}
</Tabs>

The command also takes:

- `--dry` – print the debug output to stdout instead of writing it to disk
- `--only-config` – emit only `config.json`, skipping the per-file AST and CSS
- `--outdir [dir]` – where the debug files go, `./styled-system/debug` by default
- `--silent`, `-c, --config <path>`, `--cwd <cwd>`, `--cpu-prof` and `--logfile <file>`, as on the other commands

This would generate a `debug` folder in your `config.outdir` folder with the following structure:

<FileTree>
  <FileTree.Folder name="styled-system" defaultOpen>
    <FileTree.Folder name="debug" defaultOpen>
      <FileTree.File name="config.json" />
      <FileTree.File name="src__components__Button.ast.json" />
      <FileTree.File name="src__components__Button.css" />
    </FileTree.Folder>
  </FileTree.Folder>
</FileTree>

The `config.json` file will contain the resolved config result, meaning the output after merging config presets in your
own specific options.

It can be useful to check if your config contains everything you expect for your app to be working, such as tokens or
recipes.

`*.ast.json` files will look like:

```json
[
  {
    "name": "css",
    "type": "object",
    "data": [
      {
        "transitionProperty": "all",
        "opacity": "0.5",
        "border": "1px solid",
        "borderColor": "black",
        "color": "gray.600",
        "_hover": {
          "color": "gray.900"
        },
        "rounded": "md",
        "p": "1.5",
        "_dark": {
          "borderColor": "rgba(255, 255, 255, 0.1)",
          "color": "gray.400",
          "_hover": {
            "color": "gray.50"
          }
        }
      }
    ],
    "kind": "CallExpression",
    "line": 13,
    "column": 9
  }
]
```

And the `.css` file associated would just contain the styles generated from the extraction process on that file only.

## BAMBOO_DEBUG env variable

You can prefix any of the Bamboo CLI command with the `BAMBOO_DEBUG` environment variable to show debug logs.

```bash
BAMBOO_DEBUG=* pnpm bamboo
```

This can be useful to check if a specific file is being processed or not, or if a specific function/component has been
extracted.

```
❯ BAMBOO_DEBUG=* pnpm bamboo cssgen
🎋 debug [config:path] /my-app/bamboo.config.ts
🎋 debug [ast:import] Found import { css } in /my-app/src/theme.tsx
🎋 debug [ast:Icon] { kind: 'component' }
🎋 debug [ast:css] { kind: 'function' }
🎋 debug [hrtime] Parsed /my-app/src/theme.tsx (9.66ms)
🎋 debug [ast:import] Found import { css } in /my-app/src/components/button.tsx
🎋 debug [ast:Button] { kind: 'component' }
🎋 debug [ast:css] { kind: 'function' }
🎋 debug [ast:Anchor] { kind: 'component' }
🎋 debug [hrtime] Parsed /my-app/src/components/button.tsx (4.51ms)
🎋 debug [ast:import] No import found in /my-app/src/constants.ts
🎋 debug [hrtime] Parsed /my-app/src/constants.ts (4.23ms)
🎋 debug [ast:import] Found import { css } in /my-app/src/index.tsx
🎋 debug [ast:css] { kind: 'function' }
```

## Performance profiling

If Bamboo is taking too long to process your files, you can use the `--cpu-prof` with the `bamboo`, `bamboo cssgen`,
`bamboo codegen` and `bamboo debug` commands to generate a flamegraph of the whole process, which will allow you (or us
as maintainers) to see which part of the process is taking the most time.

This will generate a `bamboo-{command}-{timestamp}.cpuprofile` file, which can be opened in tools like
[Speedscope](https://www.speedscope.app/). It is written to the directory `--cwd` resolves to, not to `process.cwd()`,
and the bare command is named `cli` rather than after a subcommand:

```bash
pnpm bamboo --cpu-prof
# → bamboo-cli-20260809T101530123Z.cpuprofile
```

## Some CSS is missing when using absolute imports

This can happen when `tsconfig` (with `paths` or `baseUrl`) or with package.json
[`#imports`](https://nodejs.org/api/packages.html#subpath-imports). Bamboo tries to automatically infer and read the
custom paths defined in `tsconfig.json` file. However, there might be scenarios that won't work.

To fix this add the `importMap` option to your `bamboo.config.js` file, setting it's value to match the way you import
the `outdir` modules.

```app.tsx
// app.tsx

import { css } from "~/styled-system/css"
// tsconfig.json paths
// -> importMap: "~/styled-system"

import { css } from "styled-system/css"
// tsconfig.json baseUrl
// -> importMap: "styled-system"

import { css } from "@my-monorepo/ui-kit/css"
// monorepo workspace package
// -> importMap: "@my-monorepo/ui-kit"

import { css } from "#styled-system/css"
// package.json#imports
// -> importMap: "#styled-system

```

```js
// bamboo.config.js

export default defineConfig({
  importMap: '~/styled-system',
})
```

This will ensure that the paths are resolved correctly, and HMR works as expected.

The rest of the troubleshooting answers live in the [FAQ](/docs/overview/faq).

## The postcss plugin sometimes seems slow or runs too frequently

This is mostly specific to the host bundler (`vite`, `webpack` etc) you're using, it is up to them to decide when to run
the postcss plugin again, and sometimes it can be more than needed for your usage. We do our best to cache the results
of the postcss plugin by checking if the filesystem or your config have actually changed, but sometimes it might not be
enough.

In those rare cases, you might want to swap to using the [CLI](/docs/installation/cli) instead, as it will always be
more performant than the postcss alternative since we directly watch for filesystem changes and only run the
extract/codegen steps when needed.

If you want to keep the convenience of having just one command to run, you can use something like `concurrently` for
that:

```json file="package.json"
{
  "scripts": {
    "dev": "concurrently \"next dev\" \"bamboo --watch\""
  }
}
```
