Summary
When deploying a Node.js Azure Functions v4 application, the function handlers are not detected by the Azure runtime if the @azure/cosmos package is imported and used. The deployment appears to succeed, but the functions list in the Azure portal is empty, and any attempt to call the endpoints results in a 404 Not Found error.
If the import { CosmosClient } from "@azure/cosmos"; line and any usage of CosmosClient are commented out, the code builds, deploys, and runs correctly, with the function handlers being detected as expected.
Environment Details:
- Azure Functions Runtime: v4
- Node.js Version: v22.x
- TypeScript Version: latest
- Bundler: tsup v8.5.0
- @azure/functions: v4.7.3
- @azure/cosmos: v4.4.1
deployment command im using func azure functionapp publish <app-name>
Expected Behavior
The deployed function app should recognize the get-user-details HTTP trigger, and the endpoint …/api/user/{userId} should be active and callable.
Actual Behavior
The deployment completes without error, but the Azure Functions runtime does not detect any functions. The “Functions” tab in the Azure Portal is empty, and all API calls return a 404 Not Found error.
Deployed Code (dist/index.js)
import { app } from "@azure/functions";
import { CosmosClient } from "@azure/cosmos";
var COSMOS_DB_ENDPOINT = process.env.COSMOS_DB_ENDPOINT;
var COSMOS_DB_KEY = process.env.COSMOS_DB_KEY;
var COSMOS_DB_NAME = process.env.COSMOS_DB_DATABASE_ID;
var cosmosConfig = {
endpoint: COSMOS_DB_ENDPOINT,
key: COSMOS_DB_KEY,
databaseId: COSMOS_DB_NAME,
containers: {
users: "Users",
}
};
// src/functions/user/userDetails.get.ts
var container = new CosmosClient({
endpoint: cosmosConfig.endpoint,
key: cosmosConfig.key,
connectionPolicy: {
enableEndpointDiscovery: true
}
}).database(cosmosConfig.databaseId).container("Items");
async function getUserDetails(request) {
try {
console.log(container);
return {
status: 200,
jsonBody: {
data: "validatedUserItem"
}
};
} catch (error) {
console.log("error: ", error);
return {
status: 500,
jsonBody: {
data: "error"
}
};
}
}
app.http("get-user-details", {
methods: ["GET"],
authLevel: "anonymous",
route: "user/{userId}",
handler: getUserDetails
});
export {
getUserDetails,
};
this is my package.json
{
"name": "my-app",
"version": "1.0.0",
"type": "module",
"main": "dist/index.js",
"scripts": {
"build": "tsup",
"dev": "npm run build -- --watch",
"clean": "rm -rf package-lock.json node_modules",
"start": "npm run build && func start --typescript",
"func:deploy": "npm run build && func azure functionapp publish waqfwakalah-dev-func"
},
"imports": {
"#common/*": "../common/src/*"
},
"dependencies": {
"@azure/cosmos": "^4.4.1",
"@azure/functions": "^4.7.3",
"zod": "^4.0.5"
},
"devDependencies": {
"@types/node": "^24.0.13",
"esbuild-plugin-alias": "^0.2.1",
"tsup": "^8.5.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
this is my tsup config:
import { defineConfig } from 'tsup'
import alias from 'esbuild-plugin-alias'
import path from 'path'
export default defineConfig({
entry: ['src/index.ts'],
outDir: 'dist',
format: 'esm',
target: 'node22',
splitting: false,
sourcemap: false,
dts: false,
external: ['@azure/functions', '@azure/cosmos'],
clean: true,
esbuildPlugins: [
alias({
'#common': path.resolve(__dirname, '../common/src'),
}),
],
})
``
The issue seems to be directly related to how the @azure/cosmos package is handled during the bundling process.
there is no errors when deploying so im not sure how to go about solving this, the only thing i can see is 0 functions found
