Azure-sdk-for-js: Cannot construct NetworkManagementClient because type incompatible @azure/arm-network

Created on 15 Mar 2020  路  7Comments  路  Source: Azure/azure-sdk-for-js

  • Package Name: @azure/arm-network
  • Package Version: 19.1.0
  • Operating system:
  • [ ] nodejs

    • version:

  • [x] browser

    • name/version: Edge dev preview

  • [x] typescript

    • version: 3.8.3

  • Is the bug related to documentation in

Describe the bug

cannot compile the following code

const subscriptionId = "xxx"
const authManager = new AuthManager({
    clientId: "xxx"
})

document.addEventListener("DOMContentLoaded", () => {
    authManager.finalizeLogin().then((res) => {
        var results = document.getElementById('results')
        if (!res.isLoggedIn) {
            results.innerText = "Not logged in"
        } else {
            const creds = res.creds
            const client = new NetworkManagementClient(creds, subscriptionId); // this line doesn't compile, see below for error.
        }
    })
})

The error is
TS2345: Argument of type 'import("D:/dev/az-api-test/node_modules/@azure/ms-rest-browserauth/node_modules/@azure/ms-rest-js/es/lib/credentials/serviceClientCredentials").ServiceClientCredentials' is not assignable to parameter of type 'import("D:/dev/az-api-test/node_modules/@azure/ms-rest-js/es/lib/credentials/serviceClientCredentials").ServiceClientCredentials'. Types of property 'signRequest' are incompatible. Type '(webResource: import("D:/dev/az-api-test/node_modules/@azure/ms-rest-browserauth/node_modules/@azure/ms-rest-js/es/lib/webResource").WebResource) => Promise<import("D:/dev/az-api-test/node_modules/@azure/ms-rest-browserauth/node_modules/@azure/ms-rest-js/es/lib/webResource").WebResource>' is not assignable to type '(webResource: import("D:/dev/az-api-test/node_modules/@azure/ms-rest-js/es/lib/webResource").WebResource) => Promise<import("D:/dev/az-api-test/node_modules/@azure/ms-rest-js/es/lib/webResource").WebResource>'. Types of parameters 'webResource' and 'webResource' are incompatible. Type 'import("D:/dev/az-api-test/node_modules/@azure/ms-rest-js/es/lib/webResource").WebResource' is not assignable to type 'import("D:/dev/az-api-test/node_modules/@azure/ms-rest-browserauth/node_modules/@azure/ms-rest-js/es/lib/webResource").WebResource'. Types of property 'headers' are incompatible. Type 'import("D:/dev/az-api-test/node_modules/@azure/ms-rest-js/es/lib/httpHeaders").HttpHeaders' is not assignable to type 'import("D:/dev/az-api-test/node_modules/@azure/ms-rest-browserauth/node_modules/@azure/ms-rest-js/es/lib/httpHeaders").HttpHeaders'. Types have separate declarations of a private property '_headersMap'.

To Reproduce

Steps to reproduce the behavior:

  1. start a new typescript web client project
  2. npm install @azure/ms-rest-browserauth and npm install @azure/arm-network
  3. try to construct NetworkManagementClient like my code above
  4. compile fails

Expected behavior

The code compiles

Screenshots
N/A

Additional context

The reason behind this is @azure/ms-rest-browserauth and @azure/arm-network use their own different @azure/ms-rest-js, which causes the error.

Question:
Many @azure js sdk libs depend on @azure/ms-rest-js. Is it possible to use Peer Dependencies, so each sdk client shares a single copy of @azure/ms-rest-js instead of having copies for everyone? And it should also solve this kind of issues.

related:
https://github.com/Azure/azure-sdk-for-js/issues/4145
https://github.com/Azure/azure-sdk-for-js/issues/4793

Mgmt Network customer-reported

All 7 comments

This seems to be another instance of a management package needing to be regenerated to work with the newer version of ms-rest-js, see #7763

@xirzec The version of Network SDK is already 2.X https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/network/arm-network/package.json#L7 why there still has problems.

Actually, this looks like a subtly different bug with types. One mistake that was made was typing public interfaces with a concrete class (WebResource) instead of using an interface type that omits private members. We have similar issues inside @azure/core-http.

@daviwil can you take a look at what is going on here specifically?

@xirzec, The difference here is that this is a browser app and therefore uses @azure/ms-rest-browserauth and not @azure/ms-rest-nodeauth where the same problem was fixed quite a while ago.

But, @azure/ms-rest-browserauth is still using v1 of @azure/ms-rest-js. See https://github.com/Azure/ms-rest-browserauth/blob/8f4a086253bb36cd50faf727ed8b7cd08fb9ff4f/package.json#L45

https://github.com/Azure/ms-rest-browserauth/issues/29 should fix that. @HarshaNalluru, can you release an update fixing this issue ms-rest-browserauth at the earliest?

Many @Azure js sdk libs depend on @azure/ms-rest-js. Is it possible to use Peer Dependencies, so each sdk client shares a single copy of @azure/ms-rest-js instead of having copies for everyone? And it should also solve this kind of issues.

The problem is that we have a mix of Azure sdks that depend on different major versions of @azure/ms-rest-js. The newer lot are incompatible with older dependency versions and vice versa. Therefore, all sdks cannot share a single copy of @azure/ms-rest-js.

@seekerlee We just released version 1.0.0 of the @azure/ms-rest-browserauth package where the dependency on @azure/ms-rest-js is updated. Please try this latest version and the issue you are seeing should be resolved.

thank you! I will give a try. @ramya-rao-a

Was this page helpful?
0 / 5 - 0 ratings