Fails to import ManagementClient in Typescript on Azure

This works locally, but crashes on Azure App Service. I’ve tried every possible way of importing managementclient and it fails. I’m also raising a support issue with my account manager.

auth0-mgmt.ts

import { ManagementClient } from "auth0"

export async function userNickname(userId: string): Promise<string | null> {
  const m = new ManagementClient({
    domain: process.env.AUTH0_ISSUER_BASE_URL ?? "",
    clientId: process.env.AUTH0_MANAGEMENT_CLIENT_ID ?? "",
    clientSecret: process.env.AUTH0_MANAGEMENT_CLIENT_SECRET ?? "",
  })
  try {
    const user = await m.users.get({ id: userId, fields: "nickname" })
    return user.data?.nickname
  } catch (error) {
    console.log("Error getting user nickname:", error)
    return null
  }
}

Here’s the stacktrace:

023-12-13T00:13:17.886814980Z import { ManagementClient } from "auth0"
2023-12-13T00:13:17.886823080Z          ^
2023-12-13T00:13:17.886827981Z
2023-12-13T00:13:17.886832481Z SyntaxError: The requested module 'auth0' does not provide an export named 'ManagementClient'
2023-12-13T00:13:17.886837181Z     at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
2023-12-13T00:13:17.886841582Z     at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
2023-12-13T00:13:17.886845982Z     at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
2023-12-13T00:13:17.886850682Z     at async loadESM (node:internal/process/esm_loader:34:7)
2023-12-13T00:13:17.886858183Z     at async handleMainPromise (node:internal/modules/run_main:66:12)
2023-12-13T00:13:17.894145144Z
2023-12-13T00:13:17.894163946Z Node.js v20.9.0

Here’s my package.json:

{
...
  "private": true,
  "type": "module",
...
  "dependencies": {
...
    "auth0": "^4.2.0",

Turns out, my Azure App Service box had an old file laying around from a really old deploy, called auth0.ts. Wow! Deleting it from wwwroot by sshing into the box fixed this issue.

Now to figure out why the az webapp up deploy command does not remove old files when it deploys! This is quite crazy – does anyone know why it behaves this way?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.