I upgraded a project from SPFx Drop 6 to RC0. I fixed the differences and now move my httpClient calls to this.context.spHttpClient.get or post methods from the 'sp-http' module.
When I'm using methods on spHttpClient properties, I have got the following errors: "error TS2345: Argument of type 'SPHttpClientConfiguration' is not assignable to parameter of type 'SPHttpClientConfiguration'"
I used the following code in my web parts:
import { SPHttpClientConfigurations } from '@microsoft/sp-http';
....
return this.context.spHttpClient.get(queryUrl, SPHttpClientConfigurations.v1).then((response: any) => {
return response.json();
}};
This code always generated on my project the following error:
C:\test-rc0>gulp
Build target: DEBUG
[16:58:32] Using gulpfile C:\test-rc0\gulpfile.js
[16:58:32] Starting gulp
[16:58:32] Starting 'default'...
[16:58:32] Starting subtask 'pre-copy'...
[16:58:32] Finished subtask 'pre-copy' after 78 ms
[16:58:32] Starting subtask 'copyStaticAssets'...
[16:58:32] Starting subtask 'sass'...
[16:58:33] Finished subtask 'sass' after 1.28 s
[16:58:33] Starting subtask 'tslint'...
[16:58:33] Starting subtask 'typescript'...
[16:58:33] [typescript] Using custom version: 2.1.5
[16:58:33] Finished subtask 'copyStaticAssets' after 1.84 s
[16:58:36] Error - typescript - src\webparts\helloWorld\HelloWorldWebPart.ts(30,78): error TS2345: Argument of type 'SPHttpClientConfiguration' is not assignable to parameter of type 'SPHttpClientConfiguration'.
[16:58:36] Finished subtask 'tslint' after 3.44 s
[16:58:36] Error - 'typescript' sub task errored after 3.5 s
"TypeScript error(s) occurred."
[16:58:36] 'default' errored after 4.9 s
[16:58:36]
[16:58:37] ==================[ Finished ]==================
Error - typescript - src\webparts\helloWorld\HelloWorldWebPart.ts(30,78): error TS2345: Argument of type 'SPHttpClientConfiguration' is not assignable to parameter of type 'SPHttpClientConfiguration'.
Error - 'typescript' sub task errored after 3.5 s
"TypeScript error(s) occurred."
[16:58:38] Project test-rc-0 version: 0.0.1
[16:58:38] Build tools version: 1.1.0
[16:58:38] Node version: v4.5.0
[16:58:38] Total duration: 8.78 s
[16:58:38] Task warnings: 1
[16:58:38] Task errors: 2
Do you have any idea about this error ? Thanks a lot for your help
Yes - we found it almost impossible to figure out where to get the values from (I had access to the source code and I still had to hunt for a while), and made a quick change before RC0. Unfortunately there was a bit of the old code that was left.
Try this
this.context.spHttpClient.get(url, SPHttpClient.configurations.v1).then ...
Hi, thanks for your answer. Always the same behavior with this code:
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
..
return this.context.spHttpClient.get(queryUrl, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => {
return response.json();
});
and the result during the compilation:
Build target: DEBUG
[09:22:52] Using gulpfile C:\test-rc0\gulpfile.js
[09:22:52] Starting gulp
[09:22:52] Starting 'default'...
[09:22:52] Starting subtask 'pre-copy'...
[09:22:52] Finished subtask 'pre-copy' after 90 ms
[09:22:52] Starting subtask 'copyStaticAssets'...
[09:22:52] Starting subtask 'sass'...
[09:22:54] Finished subtask 'sass' after 1.88 s
[09:22:54] Starting subtask 'tslint'...
[09:22:54] Starting subtask 'typescript'...
[09:22:54] [typescript] Using custom version: 2.1.5
[09:22:54] Finished subtask 'copyStaticAssets' after 2 s
[09:22:58] Error - typescript - src\webparts\helloWorld\HelloWorldWebPart.ts(30,52): error TS2345: Argument of type 'SPHttpClientConfiguration' is not assignable to parameter of type 'SPHttpClientConfiguration'.
[09:22:58] Finished subtask 'tslint' after 4.8 s
[09:22:59] Error - 'typescript' sub task errored after 4.85 s
"TypeScript error(s) occurred."
[09:22:59] 'default' errored after 6.87 s
[09:22:59]
[09:22:59] ==================[ Finished ]==================
Error - typescript - src\webparts\helloWorld\HelloWorldWebPart.ts(30,52): error TS2345: Argument of type 'SPHttpClientConfiguration' is not assignable to parameter of type 'SPHttpClientConfiguration'.
Error - 'typescript' sub task errored after 4.85 s
"TypeScript error(s) occurred."
[09:23:00] Project test-rc-0 version: 0.0.1
[09:23:00] Build tools version: 1.1.0
[09:23:00] Node version: v4.5.0
[09:23:00] Total duration: 12 s
[09:23:00] Task errors: 2
OK, that's super strange... I've written the exact same code and not had a problem. Any chance you can dump your package.json file? Also - I know this sounds foolish, but can you confirm that line 30 is "return this.context.spHttpClient.get(queryUrl, SPHttpClient...."
One or two other things to check. Can you also dump all your imports from your file? Secondly, can you delete your node_modules folder and npm i again? This error often points to multiple versions of the same library being present.
Yes, line 30 is "return this.context.spHttpClient.get(queryUrl, SPHttpClient...."
This is my package.json file:
{
"name": "test-rc-0",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"@microsoft/sp-client-base": "~0.7.0",
"@microsoft/sp-client-preview": "~0.9.0",
"@microsoft/sp-core-library": "~0.1.2",
"@microsoft/sp-http": "^0.1.2",
"@microsoft/sp-webpart-base": "~0.4.0",
"@microsoft/decorators": "~0.2.1",
"@types/react": "0.14.46",
"@types/react-addons-shallow-compare": "0.14.17",
"@types/react-addons-test-utils": "0.14.15",
"@types/react-addons-update": "0.14.14",
"@types/react-dom": "0.14.18",
"@types/es6-promise": "0.0.32",
"@types/es6-collections": "^0.5.29",
"@types/webpack-env": ">=1.12.1 <1.14.0",
"office-ui-fabric-react": "0.69.0",
"orchestrator": "^0.3.8",
"react": "0.14.8",
"react-dom": "0.14.8",
"through2": "^2.0.3",
"typescript": "^2.1.5"
},
"devDependencies": {
"@microsoft/sp-build-web": "~0.9.0",
"@microsoft/sp-module-interfaces": "~0.7.0",
"@microsoft/sp-webpart-workbench": "~0.8.0",
"gulp": "~3.9.1",
"@types/chai": ">=3.4.34 <3.6.0",
"@types/mocha": ">=2.2.33 <2.6.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
}
}
This is all the imports in my web Part:
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import * as strings from 'helloWorldStrings';
import HelloWorld from './components/HelloWorld';
import { IHelloWorldProps } from './components/IHelloWorldProps';
import { IHelloWorldWebPartProps } from './IHelloWorldWebPartProps';
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
I will check now to delete and recreate node_modules folder.
Thanks
You was right Patmil, the problem was my node_modules that was not really clean. I removed completely the folder, npm i and now the compilation is OK.
Thanks a lot for your help !
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues
Most helpful comment
You was right Patmil, the problem was my node_modules that was not really clean. I removed completely the folder, npm i and now the compilation is OK.
Thanks a lot for your help !