Skip to content

Conversation

@Kraviecc
Copy link

Hi @DigitalFlow,

I've found it difficult to make it work with typescript. When I've tried to import it with line:
import { WebApiClient } from "xrm-webapi-client" it shows error that ..../WebApiClient has no exported member 'WebApiClient'. I've fixed it by changing typings as in this pull request. Please take a look at this.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.128% when pulling 8a0579c on Kraviecc:feature/FixTypings into 040b255 on DigitalFlow:master.

@DigitalFlow
Copy link
Member

Hey @Kraviecc,

Thanks for using this library.
The typings now export as default export, can you try 'import WebApiClient from "xrm-webapi-client"'?

Kind Regards,
Florian

@Kraviecc
Copy link
Author

Thanks, that worked!

@Kraviecc Kraviecc closed this Mar 23, 2018
@Kraviecc Kraviecc deleted the feature/FixTypings branch March 27, 2018 05:50
@FixRM
Copy link

FixRM commented Oct 24, 2019

Hello! What I am doing wrong? If I use import WebApiClient from "xrm-webapi-client"; I have intelisense but I got run time error because WebApiClient is undefined. I only was able to run it using var WebApiClient = require("xrm-webapi-client"); but intelisense is not working in this case

@DigitalFlow
Copy link
Member

DigitalFlow commented Oct 24, 2019

Hi @FixRM,

The WebApiClient is exported as default export, so you have to import it as default import as well:
import * as WebApiClient from "xrm-webapi-client";
import { default as WebApiClient } from "xrm-webapi-client";

If that does not work:
Which setting do you have set as module inside your tsconfig.json? Should be "es6" and moduleResolution should be "node".

Kind Regards,
Florian

@FixRM
Copy link

FixRM commented Oct 24, 2019

Hello @DigitalFlow. In this case I have error:

Property 'Retrieve' does not exist on type 'typeof import("~/node_modules/xrm-webapi-client/Publish/WebApiClient"

@FixRM
Copy link

FixRM commented Oct 24, 2019

I'm not sure why but in this case compiler see only one property called "default" for imported WebApiClient object and this property is not available in run time as well

@DigitalFlow
Copy link
Member

@FixRM:
Sorry, can you try it like this?
import { default as WebApiClient } from "xrm-webapi-client";

@FixRM
Copy link

FixRM commented Oct 24, 2019

@DigitalFlow, same problem: TypeError: Cannot read property 'Retrieve' of undefined

@DigitalFlow
Copy link
Member

@FixRM Can you please post the version you installed and your tsconfig.json?

@FixRM
Copy link

FixRM commented Oct 24, 2019

Sure, I took latest from NPM: "xrm-webapi-client": "^3.6.16". My tsconfig:

{
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"module": "es6",
"moduleResolution": "node"
},
"include": [
"src/**/*"
]
}

Do you have working example written in TypeScript?

@DigitalFlow
Copy link
Member

DigitalFlow commented Oct 24, 2019

Hi @FixRM,

a project containing only this package.json

{ "name": "testxrmwebapiclient", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "@types/bluebird": "^3.5.28", "bluebird": "^3.7.1", "xrm-webapi-client": "^3.6.16" } } 

this test.ts file:

import { default as WebApiClient } from "xrm-webapi-client"; const test = () => { WebApiClient.Retrieve({entityName: "account"}) .then((result: any) => { }); }; 

and this tsconfig.json:

{ "compilerOptions": { "outDir": "./dist/", "sourceMap": false, "module": "ES6", "moduleResolution": "node", "baseUrl": ".", "target": "es6", "jsx": "react", "paths": { "*": [ "./node_modules/*", "./src/types/*" ] } }, "include": [ "./*" ] } 

compiles fine at my side. TSC version is 2.9.2, WebApiClient is also v3.6.16.
NPM is version 6.1.0 and node is v8.9.1.

@FixRM
Copy link

FixRM commented Oct 24, 2019

Thanks, I will try later. But will it work for modern versions of TypeScript? I use 3.6.4

@DigitalFlow
Copy link
Member

Yes it will 👍

@FixRM
Copy link

FixRM commented Oct 25, 2019

@DigitalFlow, how do you execute it? It compiles well for me too, but as I said, I got errors at runtime. Can you please check my sample repo? I try to run it from jest unit test (I know, I know I need to fake XHR) but it failed to run much earlier due to broken reference. I'm a little bit new here, so may be jest/tsc/node/etc is not configured properly - I don't know. After all I want to get browser compatible thing but it is not es6 for sure.

@DigitalFlow
Copy link
Member

@FixRM:
The import in line 2 of accounts.ts is still incorrect in your sample repo, it needs to be:
import { default as WebApiClient } from "xrm-webapi-client";

@FixRM
Copy link

FixRM commented Oct 30, 2019

@DigitalFlow, it doesn't help. It compiles well, but I still have

TypeError: Cannot read property 'Retrieve' of undefined

at runtime when running jest unit test

@FixRM
Copy link

FixRM commented Oct 30, 2019

I put suggested change in the repo. Can you please try to run test command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants