so0fka
so0fka

Reputation: 1

BuildRestClient import causes problems - Azure DevOps

Currently i'm trying to get the workitems of my azure devops server with following code:

export function geWorkitems(target: HTMLElement): void {
    // Get an instance of the client
    let client = WorkitemRestClient.getClient();
    client.getWorkItems([1]).then(definitions => {
        target.innerText = JSON.stringify(definitions)
    }
    );
}
show("workitems", geWorkitems);

when I include the needed import its gives me this error:

Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.ts(1202)

The import i am talking about:

import WorkitemRestClient = require("TFS/WorkItemTracking/RestClient");

People have been suggesting to write it this way, but it still doesnt work

import WorkitemRestClient from "TFS/WorkItemTracking/RestClient";

same with import BuildRestClient = require("TFS/Build/RestClient");

Upvotes: 0

Views: 279

Answers (1)

Benoît P
Benoît P

Reputation: 3265

Best method

Have you tried the code suggested in the error message (import {a} from "mod"):

import { geWorkitems } from "TFS/WorkItemTracking/RestClient";

Make sure you have the correct spelling and capitalisation because the export name must be the same as the import


Alternative 1

You could also try:

const WorkitemRestClient = require("TFS/WorkItemTracking/RestClient");

using require is like normal assignments so you can't use the import keyword.

require is less used nowadays and works better with the module.exports = {} notation


Alternative 2

Finally, you could keep the second import you mention:

import WorkitemRestClient from "TFS/WorkItemTracking/RestClient";

but you need to export it differently with the default keyword:

export default function geWorkitems(target: HTMLElement): void {

Upvotes: 1

Related Questions