microsoft / azure-devops-extension-sdk

Client SDK for developing Azure DevOps extensions
MIT License
125 stars 39 forks source link

Importing SDK using ESNext import results ReferenceError: define is not defined #66

Closed szimeth-jozef closed 11 months ago

szimeth-jozef commented 1 year ago

I'm building an Azure Devops extension with Vite and Svelte and I need to import this package somehow, but no success so far. The whole problem seems to be that the SDK package installed via npm is structured as a requirejs AMD library and it doesn't work well with es-modules. So my propose would be, if there is no other option to package the SDK in a similar way as for example @microsoft/signalr does. There's no need to completely change how the SDK is packaged, just to add another way it is transpiled, namely to esm.

jag-eagle-technology commented 1 year ago

Duplicate of #58 (which shouldn't be closed)

drk-mtr commented 1 year ago

As per the duplicate referenced above, I:

  1. Copied the XDM.ts and SDK.ts files from here: https://github.com/cnshenj/azure-devops-extension-sdk/tree/cnshenj/esm directly into my project.
  2. Fixed (the hacky way) the Typescript error I was seeing in SDK.ts by setting line 324 to use instance as any instead of instance.
  3. Imported into my Lit element that I'm building using Vite by using import * as SDK from './azure-devops-extension-sdk/SDK'.

It's strange that the MS docs reference the vss-web-extension-sdk, the vss extension sdk Github page references the azure-devops-extension-sdk... which then doesn't work with modern build systems. It'd be cool if MS would consider merging or maintaining the ESM version as per cnshenj's PR.

lohitakshgupta commented 11 months ago

Added multiple module support to the SDK. Please check the latest package: https://www.npmjs.com/package/azure-devops-extension-sdk/v/4.0.0. Note: This is a major version update. You need to update your package.json manually or run npm i azure-devops-extension-sdk@latest