sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

SOLUTION: SPFx 1.5.0 wrong typings in package.json causing lots of problems

Open vsoderholm opened this issue 8 years ago • 20 comments

I had some problems with MSGraphClient and AadHttpClient in 1.5.0, which after some digging seems to be caused by incorrect typings references in each and every one of the @microsoft/sp-xxx/package.json files.

it says "typings": "dist/index-internal.d.ts",

..but it should probably be "typings": "lib/index.d.ts",

Fixing this fixed my problems and made my ts-code compile again 🥇

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

Since it has main: "lib/index.js" in package.json, one would expect that the typings would be the same as the actual used code files, and not from the dist folders.

Observed Behavior

Typescript typings missing a shitload of stuff when developing your thingy.

Steps to Reproduce

for example, import {AadHttpClient} from '@microsoft/sp-http'; and then try to do const ahc = new AadHttpClient(scope, endpoint and it will incorrectly say "no 2 param constructor".

the typings in sp-http/dist/index-internal.d.ts misses this and says /* Excluded from this release type: __constructor */ on line 42.

this causes the error, but if you apply my suggested fix to use lib/index.d.ts instead, it will correctly via sp-http/lib/index.d.ts, reference the constructor on line 32 in sp-http/lib/AadHttpClient/AAdHttpClient.d.ts constructor(serviceScope: ServiceScope, resourceEndpoint: string);

Submission Guidelines

So, you could just silently fix this in the npm packages maybe? :heart:

Thanks for your contribution! Sharing is caring.

vsoderholm avatar Jun 22 '18 04:06 vsoderholm

@VesaJuvonen

vsoderholm avatar Jun 22 '18 04:06 vsoderholm

Affected packages in the @microsoft-scope:

  • node-core-library
  • sp-application-base
  • sp-component-base
  • sp-core-library
  • sp-dynamic-data
  • sp-extension-base
  • sp-http
  • sp-loader
  • sp-module-interfaces
  • sp-odata-types
  • sp-page-context
  • sp-webpart-base
  • ts-command-line

vsoderholm avatar Jun 22 '18 05:06 vsoderholm

Quick and dirty fix while waiting for ms to fix this:

  • Open folder node_modules in vscode
  • Search and replace dist/index-internal.d.ts with lib/index.d.ts
  • 💰

vsoderholm avatar Jun 22 '18 05:06 vsoderholm

This issue will be addressed in the upcoming SPFx v1.5.1 release which will be available soon.

VesaJuvonen avatar Jun 25 '18 11:06 VesaJuvonen

This should be now addressed with the 1.5.1 release, so would request to validate the situation with following. Here are short release notes for 1.5.1 release - https://twitter.com/SharePoint/status/1011689501213757441.

VesaJuvonen avatar Jun 26 '18 19:06 VesaJuvonen

@VesaJuvonen the problem is not fixed with plus beta today the package.json is still pointing to the internal index

{
  "_from": "@microsoft/[email protected]",
  "_id": "@microsoft/[email protected]",
  "_inBundle": false,
  "_integrity": "sha1-KGH5zb0zqJhEoB1PpFblpVXcLZ0=",
  "_location": "/@microsoft/sp-core-library",
  "_phantomChildren": {},
  "_requested": {
    "type": "version",
    "registry": true,
    "raw": "@microsoft/[email protected]",
    "name": "@microsoft/sp-core-library",
    "escapedName": "@microsoft%2fsp-core-library",
    "scope": "@microsoft",
    "rawSpec": "1.5.1-plusbeta",
    "saveSpec": null,
    "fetchSpec": "1.5.1-plusbeta"
  },
  "_requiredBy": [
    "/",
    "/@microsoft/sp-application-base",
    "/@microsoft/sp-client-preview",
    "/@microsoft/sp-component-base",
    "/@microsoft/sp-diagnostics",
    "/@microsoft/sp-dynamic-data",
    "/@microsoft/sp-extension-base",
    "/@microsoft/sp-http",
    "/@microsoft/sp-loader",
    "/@microsoft/sp-page-context",
    "/@microsoft/sp-webpart-base",
    "/@microsoft/sp-webpart-workbench"
  ],
  "_resolved": "https://registry.npmjs.org/@microsoft/sp-core-library/-/sp-core-library-1.5.1-plusbeta.tgz",
  "_shasum": "2861f9cdbd33a89844a01d4fa456e5a555dc2d9d",
  "_spec": "@microsoft/[email protected]",
  "_where": "C:\\Users\\vince\\Desktop\\test",
  "bundleDependencies": false,
  "dependencies": {
    "@microsoft/sp-lodash-subset": "1.5.1-plusbeta",
    "@microsoft/sp-module-interfaces": "1.5.1-plusbeta",
    "@types/es6-promise": "0.0.33",
    "@types/webpack-env": "1.13.1"
  },
  "deprecated": false,
  "description": "SharePoint Framework core libraries",
  "devDependencies": {
    "@ms/sp-build-internal-web": "~0.16.16",
    "@types/chai": "3.4.34",
    "@types/mocha": "2.2.38",
    "chai": "~3.5.0",
    "gulp": "~3.9.1"
  },
  "homepage": "http://aka.ms/spfx",
  "license": "SEE LICENSE IN \"EULA\" FOLDER",
  "main": "lib/index.js",
  "name": "@microsoft/sp-core-library",
  "scripts": {
    "build": "gulp test --clean"
  },
  "tsdoc": {
    "tsdocFlavor": "AEDoc"
  },
  "typings": "dist/index-internal.d.ts",
  "version": "1.5.1-plusbeta"
}

baywet avatar Jul 03 '18 19:07 baywet

sorry I commented at the wrong place, I meant to comment on #2067 Typings target hasn't changed, although the AAdhttpClient issue might be fixed other issues are still happening.

baywet avatar Jul 03 '18 19:07 baywet

@VesaJuvonen I tried an upgrade from 1.0.0 to 1.5.1 and I am seeing a lot of typescript errors. Any help in resolving these errors is appreciated. I deleted the node_modules folder and the package-lock.json files from my project folder and ran npm i multiple times but still have these errors.

Package.json packagejson

Typescript Errors on gulp serve typescripterrors

amarj27 avatar Jul 17 '18 20:07 amarj27

If you have any issues with typescript errors check if your tsconfig file matches the tsconfig for SPFX 1.5.1 and have a look at #1969

bastianjohn avatar Aug 22 '18 06:08 bastianjohn

Running into this as well when upgrading from 1.5.1-plusbeta to 1.6. We are using the react-search-refiners sp-dev-fx-webparts sample and we're now getting errors such as these:

Error - [tsc] src/extensions/queryStringDataSource/QueryStringDataSourceApplicationCustomizer.ts(42,18): error TS2551: Property 'dynamicDataSourceManager' does not exist on type 'ApplicationCustomizerContext'. Did you mean '_dynamicDataSourceManager'?

EDIT: Checked the tsconfig file, and it matches the contents of a default 1.6 webpart tsconfig file EDIT 2: Tried installing 1.6-plusbeta.... still getting errors, but less

tgorgdotcom avatar Sep 21 '18 16:09 tgorgdotcom

Running into this as well when upgrading from 1.5.1-plusbeta to 1.6. We are using the react-search-refiners sp-dev-fx-webparts sample and we're now getting errors such as these:

Error - [tsc] src/extensions/queryStringDataSource/QueryStringDataSourceApplicationCustomizer.ts(42,18): error TS2551: Property 'dynamicDataSourceManager' does not exist on type 'ApplicationCustomizerContext'. Did you mean '_dynamicDataSourceManager'?

EDIT: Checked the tsconfig file, and it matches the contents of a default 1.6 webpart tsconfig file EDIT 2: Tried installing 1.6-plusbeta.... still getting errors, but less

I am facing the same issue while accessing any application customizer or webpart which is utilizing dynamic data source binding. Below is the error description with one of the samples: [21:45:23] Error - [tsc] src/extensions/searchExtension/SearchExtensionApplicationCustomizer.ts(14,10): error TS2305: Module '"C:/NodeJS/sp-dev-fx-extensions-master/samples/react-application-search-dynamicdata/node_modules/@microsoft/sp-dynamic-data/dist/index-internal"' has no exported member 'IDynamicDataPropertyDefinition'. [21:45:23] Error - [tsc] src/webparts/searchWebPart/SearchWebPartWebPart.ts(14,10): error TS2305: Module '"C:/NodeJS/sp-dev-fx-extensions-master/samples/react-application-search-dynamicdata/node_modules/@microsoft/sp-dynamic-data/dist/index-internal"' has no exported member 'IDynamicDataSource'.

I changed all references back to 1.5.1-plusbeta from 1.6.0, but still the erroe persists. Any suggestions and guidance will be really helpful.

Ash11282 avatar Sep 29 '18 02:09 Ash11282

This still doesn't appear to be fixed.....is there a fix in the near future for this?

alexkolson avatar Dec 05 '18 19:12 alexkolson

Build 1.7.0 has the official / final / supported code for dynamic data.

Can you update your packages to work with the final version of the code and see if that solves the issue?

patmill avatar Dec 05 '18 20:12 patmill

@patmill Hey I really appreciate the response so quick! Completely awesome! I am using 1.7.0 already though. :(

alexkolson avatar Dec 05 '18 20:12 alexkolson

OK, well that's good. Can you give me a snippet of the code that isn't working for you? It's likely that we just moved the final location of the interfaces. Although IDynamicDataSource should be exported from @microsoft/sp-dynamic-data at version 1.7.0

https://docs.microsoft.com/en-us/javascript/api/sp-dynamic-data?view=sp-typescript-latest

patmill avatar Dec 05 '18 20:12 patmill

@patmill Hey I really appreciate the response so quick! Completely awesome! I am using 1.7.0 already though. :(

I am no longer getting errors with 1.7 package. I would suggest you to create a fresh project with 1.7 and then add specific components to the project. This way you will have updated tslint (which should now be at root level) and other files.

Ash11282 avatar Dec 05 '18 20:12 Ash11282

Wow quick again! How awesome is that! Thanks a ton @patmill!

So it's actually "overriding" the logger that Im having issues with. Says no _initialize is present on Log class cause its commented out in the exposed typings.

Im just following the advice from https://blog.mastykarz.nl/logging-sharepoint-framework/

My issue is pretty much the exact same as #2067

alexkolson avatar Dec 05 '18 20:12 alexkolson

I mean, I get that underscore methods are private and it's not the brightest idea to try and use them...and you were fully within expected parameters to remove this method from the public interface but then how does one override / create a custom logger in sharepoint framework? Thanks again! Really impressed with your responsiveness! Thanks for helping make sharepoint framework awesome!

alexkolson avatar Dec 05 '18 20:12 alexkolson

OK, so unpacking this particular bug, it sounds like it (in general) is fixed (at least as far as the title, etc. is concerned), and now your issue is a dupe of #2067 . I'll close this one, and move over to that one (reopen if that isn't correct).

patmill avatar Dec 05 '18 21:12 patmill

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

msft-github-bot avatar Jan 27 '20 06:01 msft-github-bot