Compile Azure Functions within monorepo projects

I tried to write an Azure Functions in a monorepo project written in Typescript, following the Azure Functions guide.

However, when running $ pnpm start to run the azure functions locally, it showed error about the import path:

Error [ERR_MODULE_NOT_FOUND]: Worker was unable to load entry point "dist/src/functions/example.js": 
Cannot find module '/workspace/depot/packages/prisma/node_modules/data/entity' 
imported from /workspace/depot/packages/prisma/task.js

I am sure that there is something wrong with the module resolution of these projects, but no idea where the issue is and how to fix it. Because of the requirements of azure function tools (or may not), the function file has to be in ES module, and this requires the .js extension of the import path for all its dependencies? But the import paths in the generated JS codes in prisma and data projects are still in Typescript style. Any idea how to fix it?

Btw, any idea how to make the import path in apps/worker/src/functions/example.ts cleaner? I think it would be much better to keep 'prisma/task' rather than 'prisma/dist/task.js'.

More details below. Let me know if anything else is needed to solve this issue.

Here is the project structure:

.
├── apps
│   └── worker
|       ├── src/functions
|       |   └── example.ts
|       ├── package.json
|       └── tsconfig.json
├── packages
│   ├── prisma
|   |   ├── client
|   |   |   ├── index.js
|   |   |   ...
|   |   |
|   |   ├── prisma.schema
|   |   ├── task.ts
|   |   ├── package.json
|   |   └── tsconfig.json
│   └── data
|       ├── entity.ts
|       ├── package.json
|       └── tsconfig.json
└── tsconfig.json

The project packages/prisma imports project packages/data, and the apps/worker imports packages/prisma to connect to the database:

/// apps/worker/src/functions/example.ts

// This module won't be found.
import { getTask } from 'prisma/task';

// This works.
import { getTask } from 'prisma/dist/task.js';
/// packages/prisma/task.ts

// I need to keep this because it is also used by other projects.
import { Entity } from 'data/entity';

Generated packages/prisma/task.ts js code:

/// packages/prisma/dist/task.js

// Module import path is not changed.
import { Entity } from 'data/entity';

Here is the package.json file for worker project:

/// apps/worker/package.json
{
  ...
  "main": "dist/src/functions/*.js",
  "type": "module",  // required by azure function tools?
  "scripts": {
    "build": "tsc -b",
    "prestart": "pnpm run clean && pnpm run build",
    "start": "func start"
  },
  "dependencies": {
    "prisma": "workspace:*",
    "data": "workspace:*",
    ...
  },
  "devDependencies": {
    "azure-functions-core-tools": "^4.x",
    ...
  }
}

Here are the tsconfig.ts files:

/// tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "target": "es2021",
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "outDir": "dist",
    "rootDir": ".",
    "jsx": "preserve",
    "incremental": true
  }
}
/// apps/worker/tsconfig.json
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "sourceMap": true
  },
  "references": [
    { "path": "../../packages/data" },
    { "path": "../../packages/prisma" }
  ]
}

/// packages/prisma/tsconfig.json

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "noEmit": false,
    "composite": true
  },
  "include": ["**/*.ts", "**/*.d.ts", "**/*.js"],
  "exclude": ["node_modules", "client/**/*", "dist"],
  "references": [{ "path": "../data" }]
}
/// packages/data/tsconfig.json

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "noEmit": false,
    "composite": true
  },
  "include": ["**/*.ts"],
  "exclude": ["node_modules", "dist"]
}

For the packages/prisma/client, it is generated by the prisma from the prisma.schema file, and it should not be re-compiled by tsc and we can just copy/paste it to the dist/ directory I guess?

New contributor

Palt Mp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật