GʀᴜᴍᴘʏCᴀᴛ
GʀᴜᴍᴘʏCᴀᴛ

Reputation: 8972

Why is my util package not recognized in my Turborepo?

When I call a function from my utils directory:

import {cn} from '@repo/utils'

I continue to get the error:

Cannot find module '@repo/utils' or its corresponding type declarations.ts(2307)

from apps/web/page.tsx

apps/web/package.json

{
  "name": "web",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "type-check": "tsc --noEmit"
  },
  "dependencies": {
    "@repo/ui": "workspace:*",
    "@repo/utils": "workspace:*",
    "next": "15.1.3",
    "react": "19.0.0",
    "react-dom": "19.0.0"
  },
  "devDependencies": {
    "@repo/config-eslint": "workspace:*",
    "@repo/config-tailwind": "workspace:*",
    "@repo/config-typescript": "workspace:*",
    "@next/eslint-plugin-next": "^14.2.3",
    "@types/node": "22.10.1",
    "@types/react": "19.0.0",
    "@types/react-dom": "19.0.1",
    "autoprefixer": "^10.4.18",
    "postcss": "^8.4.35",
    "tailwindcss": "3.4.1",
    "typescript": "5.5.4"
  }
}

but I've followed the documentation on internal packages with:

utils

setup: packages/utils/

package.json

{
  "name": "@repo/utils",
  "version": "1.0.0",
  "private": true,
  "sideEffects": false,
  "files": [
    "dist"
  ],
  "type": "module",
  "scripts": {
    "build": "tsc",
    "dev": "tsc -w",
    "lint": "eslint . --max-warnings 0"
  },
  "exports": {
    "./utils": "./dist/index.tsx"
  },
  "dependencies": {
    "clsx": "^2.1.1",
    "tailwind-merge": "^2.6.0"
  },
  "devDependencies": {
    "@repo/config-eslint": "workspace:*",
    "@repo/config-typescript": "workspace:*",
    "@types/eslint": "9.6.1",
    "@types/node": "22.10.1",
    "eslint": "9.13.0",
    "typescript": "5.5.4"
  }
}

and I've tried the variation of:

  "exports": {
    "./utils": "./src/index.tsx"
  },

packages/utils/src/index.tsx

import {type ClassValue, clsx} from 'clsx'
import {twMerge} from 'tailwind-merge'

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

when I try pnpm i nothing is flagged as an error

tsconfig.json

{
  "extends": "@repo/config-typescript/base.json",
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": "src",
    "strict": false
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}

turbo.json

{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "inputs": ["$TURBO_DEFAULT$", ".env*"],
      "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
    },
    "lint": {},
    "type-check": {},
    "dev": {
      "cache": false,
      "persistent": true
    },
    "clean": {
      "cache": false
    }
  }
}

Research

Why am I not able to bring in my function from my utils package?

Upvotes: 0

Views: 79

Answers (0)

Related Questions