SOLVED

error TS2307: Cannot find module '@microsoft/sp-webpart-base'

Deleted
Not applicable

I am trying to create a reusable library within a SPFx project and I used the gulp tasks created by Waldek here:

https://github.com/waldekmastykarz/spfx-sample-dllcode/blob/b3fe3e208d7271f5f52b64cd66522207ccb4ee1c...

 

1.png

 

However I get the following errors which I know exactly what it means, but during coding time, I Dont see they get any warnings

 

 

 

C:/Users/valencil/Repos/TypescriptDesignPatternsInSPFx/node_modules/@types/requirejs/index.d.ts(416,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'requir
e' must be of type 'NodeRequire', but here has type 'Require'.
src\libraries\spdataaccess\dataproviders\IDataProvider.ts(1,33): error TS2307: Cannot find module '@microsoft/sp-webpart-base'.
src\libraries\spdataaccess\dataproviders\sharepointDataProvider.ts(5,8): error TS2307: Cannot find module '@microsoft/sp-http'.
src\libraries\spdataaccess\dataproviders\sharepointDataProvider.ts(6,33): error TS2307: Cannot find module '@microsoft/sp-webpart-base'.
src\libraries\spdataaccess\dataproviders\sharepointDataProvider.ts(20,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
src\libraries\spdataaccess\dataproviders\sharepointDataProvider.ts(25,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
src\libraries\spdataaccess\dataproviders\sharepointDataProvider.ts(29,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
src\libraries\spdataaccess\dataproviders\sharepointDataProvider.ts(34,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.

 

Any idea?

2 Replies

btw., my package.json 

 

{
  "name": "typescript-design-patterns-in-sp-fx",
  "version": "0.0.1",
  "private": true,
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "build": "gulp bundle",
    "clean": "gulp clean",
    "test": "gulp test"
  },
  "dependencies": {
    "@microsoft/sp-core-library": "~1.2.0",
    "@microsoft/sp-webpart-base": "^1.2.0",
    "@types/react": "15.0.38",
    "@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/webpack-env": ">=1.12.1 <1.14.0",
    "react": "15.4.2",
    "react-dom": "15.4.2",
    "sp-pnp-js": "^3.0.0"
  },
  "devDependencies": {
    "@microsoft/sp-build-web": "~1.2.0",
    "@microsoft/sp-module-interfaces": "~1.2.0",
    "@microsoft/sp-webpart-workbench": "~1.2.0",
    "@types/chai": ">=3.4.34 <3.6.0",
    "@types/mocha": ">=2.2.33 <2.6.0",
    "gulp": "~3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-typescript": "^3.2.2",
    "gulp-util": "^3.0.8",
    "through2": "^2.0.3"
  }
}
best response
Solution

The base project you're using, has been created using a prerelease version (v0.2.0) of the SharePoint Framework. In your case, you're using v1.2.0 of the SharePoint Framework, which is why your seeing various errors.

 

What you could try, is to carefully port the different pieces and see how the different types change over time.

 

What's even more important though, is that at this time, deploying SharePoint Framework libraries to the App Catalog is not supported and you will get an error if you try to do it. Because of it, I'd recommend you build a regular NPM package for the time being, and if still necessary, convert it to a SharePoint Framework library once it's supported.

1 best response

Accepted Solutions
best response
Solution

The base project you're using, has been created using a prerelease version (v0.2.0) of the SharePoint Framework. In your case, you're using v1.2.0 of the SharePoint Framework, which is why your seeing various errors.

 

What you could try, is to carefully port the different pieces and see how the different types change over time.

 

What's even more important though, is that at this time, deploying SharePoint Framework libraries to the App Catalog is not supported and you will get an error if you try to do it. Because of it, I'd recommend you build a regular NPM package for the time being, and if still necessary, convert it to a SharePoint Framework library once it's supported.

View solution in original post