0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2024-05-03

概要

前回はfunctions内でのエイリアス設定を行った。
今回は、モノレポで試してみることにする。2024/07/21 フォルダを分けているだけ。Turborepoで管理のときの設定はこちら
例として、Prismaを別フォルダとしてエイリアス設定を行う。

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

コード修正

api/tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "dist",
-   "rootDir": ".",
    "sourceMap": true,
    "strict": true,
    "paths": {
      "@yakumi-api/*": ["./src/*"],
+      "@yakumi-prisma/*": ["../packages/prisma/*"],
    }
  }
}
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": "*"
  }
}

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

原因

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 '***'.エラーが出る
Type error: Module '"@prisma/client"' has no exported member 'Product'
deploying-a-turborepo-next-js-app-to-azure-static-web-app
Nuxt3アプリをAzure Static Web Appsにデプロイする
Prisma client

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?