# For pnpm
typescript:
  compileCommand:
    - pnpm
    - install
```

This tells Speakeasy to use pnpm instead of npm when building the SDK, which is especially important in monorepos where pnpm's strict module resolution helps prevent dependency confusion issues.

<Callout title="Related Guide">
  For more detailed information about configuring pnpm as your default package
  manager, see our [Using PNPM guide](/guides/sdks/pnpm-default).
</Callout>

## Putting it all together - a real-world example

This is an example of how a developer may set up a monorepo with a Speakeasy SDK:

```
my-monorepo/
├── package.json
├── pnpm-workspace.yaml
├── tsconfig.json
├── packages/
│   ├── api-sdk/         # Speakeasy-generated SDK
│   │   ├── package.json
│   │   ├── tsconfig.json
│   │   └── gen.yaml
│   ├── frontend/        # Frontend application using the SDK
│   │   ├── package.json
│   │   └── tsconfig.json
│   └── backend/         # Backend service using the SDK
│       ├── package.json
│       └── tsconfig.json
```

pnpm-workspace.yaml:

```yaml
packages:
  - "packages/*"
```

frontend/package.json:

```json
{
  "dependencies": {
    "api-sdk": "workspace:*"
  }
}
```

gen.yaml:

```yaml
typescript:
  moduleFormat: esm
  compileCommand:
    - pnpm
    - install
    - and
    - pnpm
    - build
```

This setup gives:

1. A consistent dependency tree with pnpm's strict module resolution
2. ESM modules for maximum compatibility
3. pnpm for package management

## Best practices for TypeScript SDKs in monorepos

Beyond the specific issues above, here are some general best practices:

- **Use workspace references**: Always reference your SDK using workspace syntax (`workspace:*`) rather than local file paths
- **Consistent TypeScript versions**: Use the same TypeScript version across all packages
- **Shared tsconfig**: Create a base tsconfig.json that all packages extend
- **Centralized types**: Consider creating a shared types package for common interfaces
- **Integration tests**: Write tests that verify the SDK works correctly with other packages

## Related documentation

For more information on configuring Speakeasy TypeScript SDKs, check out:

- [TypeScript SDK Design](https://www.speakeasy.com/docs/languages/typescript/methodology-ts)
- [Configuring Module Format](https://www.speakeasy.com/docs/customize/typescript/configuring-module-format)
- [TypeScript SDK Reference](https://www.speakeasy.com/docs/languages/typescript/feature-support)
- [Model Validation and Serialization](https://www.speakeasy.com/docs/customize/typescript/model-validation-and-serialization)
- [TypeScript Configuration](https://www.speakeasy.com/docs/speakeasy-reference/generation/ts-config)