{"id":15712,"library":"ms-rest-azure","title":"Azure Client Runtime for AutoRest Generated Node.js Libraries","description":"ms-rest-azure served as the foundational client runtime for Node.js Azure client libraries generated using the AutoRest toolchain. It provided essential infrastructure for handling HTTP requests, error responses, tracing, and Azure-specific authentication mechanisms such as Device Token, Service Principal, and Managed Identity. The package (version 3.0.2, last published approximately four years ago) was part of the older `azure-sdk-for-node` repository. As of March 2023, this package, along with many others in its repository, has been officially deprecated. The Azure SDK team has transitioned to a new generation of SDKs (`@azure/*` packages) that offer isomorphic capabilities (browser and Node.js support), consistent design guidelines, and native TypeScript support. Users are strongly encouraged to migrate to the newer `@azure/core-client` and `@azure/identity` packages for modern Azure development.","status":"deprecated","version":"3.0.2","language":"javascript","source_language":"en","source_url":"git@github.com:Azure/azure-sdk-for-node","tags":["javascript","node","microsoft","autorest","azure","clientruntime","typescript"],"install":[{"cmd":"npm install ms-rest-azure","lang":"bash","label":"npm"},{"cmd":"yarn add ms-rest-azure","lang":"bash","label":"yarn"},{"cmd":"pnpm add ms-rest-azure","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core HTTP client runtime providing basic request/response handling and serialization. ms-rest-azure builds upon this.","package":"ms-rest","optional":false}],"imports":[{"note":"While this pattern works, prefer ESM imports. Note that authentication functions have largely moved to @azure/ms-rest-nodeauth and then @azure/identity in the modern SDK.","wrong":"const { loginWithServicePrincipalSecret } = require('ms-rest-azure');","symbol":"loginWithServicePrincipalSecret","correct":"import { loginWithServicePrincipalSecret } from 'ms-rest-azure';"},{"note":"Used for interactive login flows. This functionality, like other authentication methods, has been migrated to @azure/ms-rest-nodeauth and ultimately to @azure/identity in the newer Azure SDKs.","wrong":"const { DeviceTokenCredentials } = require('ms-rest-azure');","symbol":"DeviceTokenCredentials","correct":"import { DeviceTokenCredentials } from 'ms-rest-azure';"},{"note":"The base client for interacting with Azure services. In the modern SDK, this is largely replaced by `@azure/core-client`.","wrong":"const { AzureServiceClient } = require('ms-rest-azure');","symbol":"AzureServiceClient","correct":"import { AzureServiceClient } from 'ms-rest-azure';"}],"quickstart":{"code":"import { loginWithServicePrincipalSecret } from 'ms-rest-azure';\nimport { SubscriptionClient } from '@azure/arm-subscriptions'; // Example: using a client that depends on ms-rest-azure\n\nconst clientId = process.env.AZURE_CLIENT_ID ?? '';\nconst secret = process.env.AZURE_CLIENT_SECRET ?? '';\nconst domain = process.env.AZURE_TENANT_ID ?? ''; // Also known as tenantId\nconst subscriptionId = process.env.AZURE_SUBSCRIPTION_ID ?? '';\n\nasync function authenticateAndListSubscriptions() {\n  if (!clientId || !secret || !domain || !subscriptionId) {\n    console.error('Please set AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID, and AZURE_SUBSCRIPTION_ID environment variables.');\n    return;\n  }\n\n  try {\n    console.log('Attempting to log in with Service Principal...');\n    const credentials = await loginWithServicePrincipalSecret(clientId, secret, domain);\n    console.log('Successfully authenticated.');\n\n    const client = new SubscriptionClient(credentials);\n    const subscriptions = await client.subscriptions.list();\n\n    console.log('Azure Subscriptions:');\n    for await (const sub of subscriptions) {\n      console.log(`- ${sub.displayName} (${sub.subscriptionId})`);\n    }\n  } catch (err) {\n    console.error('Authentication or API call failed:', err);\n  }\n}\n\nauthenticateAndListSubscriptions();\n","lang":"typescript","description":"Demonstrates authenticating with Azure using a service principal and listing subscriptions, typical for older SDK clients."},"warnings":[{"fix":"Migrate to the modern Azure SDK for JavaScript/TypeScript. Specifically, for authentication, use `@azure/identity` (e.g., `DefaultAzureCredential`). For client functionality, use `@azure/core-client` or service-specific `@azure/*` client libraries.","message":"The `ms-rest-azure` package was officially deprecated as of March 2023, along with many other packages in the `azure-sdk-for-node` repository. It no longer receives active development, new features, or security updates. Users should migrate to the new Azure SDK for JavaScript/TypeScript packages (`@azure/*`).","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace calls to `ms-rest-azure` authentication functions with their counterparts in `@azure/identity`. For instance, `new ClientSecretCredential(tenantId, clientId, clientSecret)` instead of `loginWithServicePrincipalSecret`.","message":"Authentication methods like `loginWithServicePrincipalSecret` and `interactiveLogin` were initially moved from `ms-rest-azure` to `@azure/ms-rest-nodeauth` to support isomorphic libraries. `@azure/ms-rest-nodeauth` itself is now deprecated in favor of `@azure/identity`.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"If you must use this package in an ESM context, consider using a build tool to transpile, or convert your project to CJS. However, the recommended fix is to migrate to the newer `@azure/*` packages which offer full ESM support.","message":"`ms-rest-azure` was primarily designed for Node.js and CommonJS (CJS) environments as part of the older Azure SDKs. Modern JavaScript development often uses ECMAScript Modules (ESM), which can lead to compatibility issues when mixing `require()` and `import` statements or running in pure ESM projects.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure your Node.js environment is version 6.10 or newer. Ideally, use a currently supported Node.js LTS version for security and compatibility with modern libraries.","message":"Versions of `ms-rest-azure` (via its dependency `ms-rest`) require Node.js version 6.10 or higher. Running on older Node.js environments will result in compatibility errors due to ES6 syntax and features introduced in those versions.","severity":"gotcha","affected_versions":"<3.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure that the credential object matches the expected interface of the client library. If using `ms-rest-azure` based clients, use `ms-rest-azure` or `@azure/ms-rest-nodeauth` credentials. If using modern `@azure/*` clients, use `@azure/identity` credentials. Avoid mixing credential types across different SDK generations.","cause":"This error often occurs when an incompatible credential object is passed to a client library, frequently due to mixing versions of `@azure/ms-rest-nodeauth` or `ms-rest-azure` or attempting to use a modern `@azure/identity` credential with an older client.","error":"Error: credentials argument needs to implement signRequest method"},{"fix":"Verify correct installation (`npm install ms-rest-azure`) and import syntax. For CommonJS, ensure `const msRestAzure = require('ms-rest-azure');` and then `msRestAzure.loginWithServicePrincipalSecret`. For ESM, use `import * as msRestAzure from 'ms-rest-azure';` or named imports `import { loginWithServicePrincipalSecret } from 'ms-rest-azure';`. If still problematic, consider migrating to `@azure/identity`.","cause":"This error can occur if `ms-rest-azure` is imported incorrectly (e.g., trying to destructure a default export as named), or if the package is truly not installed or corrupted. It's also common if attempting to use older `ms-rest-azure` functions in an environment where they are not correctly resolved, especially in newer ESM contexts where `require` patterns are discouraged.","error":"TypeError: msRestAzure.loginWithServicePrincipalSecret is not a function"}],"ecosystem":"npm"}