microsoft / azure-devops-extension-sdk

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

define is not a function #58

Closed Shadowner closed 1 year ago

Shadowner commented 2 years ago

I'm trying to develop an extension for Azure DevOps. But whenever I try to use the SDK it pop an error in the console :

Uncaught TypeError: define is not a function

I've tried to manually add requestjs/requirejs but it still doesn't work

here is the little code that I use

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <div id="root"></div>
    <!-- <script src="./WorkItemFormPage.tsx" type="module"></script> -->
    <script type="module">
      import * as SDK from "azure-devops-extension-sdk";

      SDK.init();
    </script>
  </body>
</html>

If you need more details about the code, feel free to ask!

gburning commented 2 years ago

Are you using any build tools? I'm using Vite and had to manually include require.js. Seems to have something to do with what Vite calls Dependency Pre-Bundling. Not entirely satisfied though as I still don't quite understand why this happens.

gburning commented 2 years ago

Doesn't seem to have worked after all, still digging into this.

gburning commented 2 years ago

Ok, so as it turns out this was because the library is built as an AMD module, which Vite does not natively support. For my use case I ended up making use of the code from @cnshenj in their pull request so I can use it as an ES module.

If any of the maintainers read this, please merge this pull request as it seems like no brainer in 2022 to use ES modules.

Shadowner commented 1 year ago

Totally what I also saw, it's been a while and totally forgot this issues, thank's for your time !

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