モノレポのAzure Functions (Node Typescript) のtsconfigにpathsのエイリアス設定を行ったメモ

## 概要
[前回](https://qiita.com/hibohiboo/items/d40b27aaec40e0f67148)はfunctions内でのエイリアス設定を行った。
今回は、モノレポで試してみることにする。**2024/07/21 フォルダを分けているだけ。Turborepoで管理のときの設定は[こちら](https://qiita.com/hibohiboo/items/a678e8af01b6fef21709)**
例として、[Prisma](https://qiita.com/hibohiboo/items/8598d44e64562ce37ebd)を別フォルダとしてエイリアス設定を行う。

...Prismaのせいで余分な設定を多めにした気がする。
ともかく、動くことを確認できた。

## コード修正
```diff:api/tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "dist",
-   "rootDir": ".",
    "sourceMap": true,
    "strict": true,
    "paths": {
      "@yakumi-api/*": ["./src/*"],
+      "@yakumi-prisma/*": ["../packages/prisma/*"],
    }
  }
}
```

```diff:packages/prisma/package.json
{
  "name": "@yakumi/prisma-zod",
  "scripts": {
    "bundle": "esbuild --bundle generated/zod/index.ts --outfile=dist/index.js --target=node20 --format=cjs",
+   "build": "prisma generate",
    "migration": "prisma migrate dev --create-only --name newMigration",
    "deploy": "prisma migrate deploy"
    "ncu": "ncu -u"
  },
  "dependencies": {
    "@prisma/client": "^5.13.0",
    "zod": "^3.23.4"
  },
  "devDependencies": {
    "esbuild": "^0.20.2",
    "prisma": "^5.13.0",
    "zod-prisma-types": "^3.1.6",
    "@yakumi/tsconfig": "*"
  }
}

```


```diff:api/package.json
{
  "name": "api",
  "version": "1.0.0",
  "description": "",
  "scripts": {
+   "prebuild": "cd ../packages/prisma && npm run build",
    "build": "tsc && tsc-alias",
    "watch": "tsc -w",
    "clean": "rimraf dist",
    "predev": "npm run clean && npm run build",
    "dev": "func start --port 7071"
  },
  "dependencies": {
    "@azure/functions": "^4.4.0",
    "@azure/storage-blob": "^12.17.0",
    "date-fns": "^3.6.0"
  },
  "devDependencies": {
    "@types/node": "^20.x",
    "rimraf": "^5.0.5",
    "tsc-alias": "^1.8.8",
    "typescript": "^5.4.5"
  },
-  "main": "dist/src/functions/*.js"
+  "main": "dist/api/src/functions/*.js"
}
```

## 試行錯誤
### ローカルでは動くのにパイプラインでは動かないやつ
#### 404 Not Found - GET https://registry.npmjs.org
```
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@yakumi%2fprisma-zod - Not found
npm ERR! 404 
npm ERR! 404  '@yakumi/prisma-zod@*' is not in this registry.
npm ERR! 404
```

原因

```diff:api/package.json
  "dependencies": {
-  "'@yakumi/prisma-zod": "*"
```

Functionsのビルドのときに、モノレポの構成が崩れているっぽい

#### .Prisma' has no exported member 

```
api:build: ../packages/prisma/generated/zod/index.ts(43,60): error TS2694: Namespace '"/working_dir/node_modules/.prisma/client/default".Prisma' has no exported member 'YakumiCharacterSelect'.
```

原因

Functionsのビルドの時に、prisma generateで作成されたものが失われているっぽい。
あらためて、ビルド前にはprisma generateを明示することで回避可能。



## 参考
[Next.jsをVercelにデプロイするとType error: Module '"@prisma/client"' has no exported member '***'.エラーが出る](https://qiita.com/naoyuki2/items/f199c76df4657b4b174c)
[Type error: Module '"@prisma/client"' has no exported member 'Product'](https://stackoverflow.com/questions/78289132/type-error-module-prisma-client-has-no-exported-member-product)
[deploying-a-turborepo-next-js-app-to-azure-static-web-app](https://stackoverflow.com/questions/76890164/deploying-a-turborepo-next-js-app-to-azure-static-web-app)
[Nuxt3アプリをAzure Static Web Appsにデプロイする](https://zenn.dev/yamaday/articles/nuxt-azure-static-web-apps)
[Prisma client](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client)