I have a monorepo project using bun workspaces. I have app/web and app/api, packages/api-client, packages/shared, packages/eslint-config.
I want to install typescript, how would I go about doing this? do i install typescript in each app and package or do I use peer dependency, what's the best approach for common npm packages?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
For a monorepo with Bun workspaces, the best approach is to install TypeScript (and other common development dependencies) at the root level of your monorepo. This way, all your workspaces can share the same version without duplication.
Here's how to set it up:
Install TypeScript at the root
bash
# In your monorepo root directory
bun add -d typescript
This installs TypeScript as a dev dependency in your root package.json. All workspaces will have access to it.
Development tools (TypeScript, ESLint, Prettier, testing frameworks): Install at the root
Runtime dependencies that are truly shared: Can go at the root, but be careful
Workspace-specific dependencies: Install in the specific workspace
For example:
bash
# Root level (shared dev dependencies)
bun add -d typescript eslint prettier vitest @types/node
# Workspace specific
cd app/web
bun add react react-dom
bun add -d @types/react @types/react-dom
cd ../api
bun add express
bun add -d @types/express
Why not peer dependencies?
Peer dependencies are meant for packages that will be published and need to work with a consumer's version of a dependency. Since your workspaces are internal to your monorepo, you don't need peer dependencies for TypeScript or other build tools.