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

Struggling with React 16/Office UI Fabric React in SPFX

Open pkbullock opened this issue 8 years ago • 10 comments

Category

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

Expected or Desired Behavior

I would like to use the React 16/Office UI Fabric with SPFX but struggling with getting SPFX to build.

Observed Behavior

Cannot build the solution.

The documentation page for https://docs.microsoft.com/en-us/sharepoint/dev/spfx/office-ui-fabric-integration is quite far out of date. Can this be updated?

Also, this thread indicated that typescript isn't up to date to support the latest React 16/Office UI Fabric: https://github.com/OfficeDev/office-ui-fabric-react/issues/7054

I have tried the suggestion and does not work.

[14:17:55] Using gulpfile C:\git\tfs\intranet-web-parts\alerts\gulpfile.js [14:17:55] Starting gulp [14:17:55] Starting 'build'... [14:17:55] Starting subtask 'configure-sp-build-rig'... [14:17:55] Finished subtask 'configure-sp-build-rig' after 5.71 ms [14:17:55] Starting subtask 'pre-copy'... [14:17:55] Finished subtask 'pre-copy' after 49 ms [14:17:55] Starting subtask 'copy-static-assets'... [14:17:55] Starting subtask 'sass'... [14:17:55] Finished subtask 'copy-static-assets' after 148 ms [14:17:55] Finished subtask 'sass' after 231 ms [14:17:55] Starting subtask 'tslint'... [14:17:55] [tslint] tslint version: 5.9.1 [14:17:55] Starting subtask 'tsc'... [14:17:55] [tsc] typescript version: 2.4.2 [14:17:58] Error - [tsc] node_modules/office-ui-fabric-react/node_modules/@uifabric/merge-styles/lib/IStyleSet.d.ts(15,67): error TS1005: ';' expected. [14:17:58] Error - [tsc] node_modules/office-ui-fabric-react/node_modules/@uifabric/merge-styles/lib/IStyleSet.d.ts(15,114): error TS1005: '(' expected. [14:17:58] Error - [tsc] node_modules/office-ui-fabric-react/node_modules/@uifabric/merge-styles/lib/IStyleSet.d.ts(15,136): error TS1005: '(' expected. [14:17:58] Error - 'tsc' sub task errored after 2.4 s exited with code 2 [14:17:58] 'build' errored after 2.91 s [14:17:58] [14:17:58] ==================[ Finished ]================== Error - [tsc] node_modules/office-ui-fabric-react/node_modules/@uifabric/merge-styles/lib/IStyleSet.d.ts(15,67): error TS1005: ';' expected. Error - [tsc] node_modules/office-ui-fabric-react/node_modules/@uifabric/merge-styles/lib/IStyleSet.d.ts(15,114): error TS1005: '(' expected. Error - [tsc] node_modules/office-ui-fabric-react/node_modules/@uifabric/merge-styles/lib/IStyleSet.d.ts(15,136): error TS1005: '(' expected. Error - 'tsc' sub task errored after 2.4 s exited with code 2 [14:17:59] Finished subtask 'tslint' after 3.63 s [14:17:59] Project spfx-alerts version:0.0.1 [14:17:59] Build tools version:3.8.33 [14:17:59] Node version:v8.11.4 [14:17:59] Total duration:7.81 s [14:17:59] Task errors:4

Steps to Reproduce

Setup SPFX with the following dependencies:

  • Setup SPFX Web Part with React

  • Remove @microsoft/[email protected]

  • Use dependencies:

  • "dependencies": { "@microsoft/sp-core-library": "1.7.0", "@microsoft/sp-lodash-subset": "1.7.0", "@microsoft/sp-webpart-base": "1.7.0", "@types/es6-promise": "0.0.33", "@types/react": "16.4.2", "@types/react-dom": "16.0.5", "@types/webpack-env": "1.13.1", "office-ui-fabric-react": "6.57.0", "react": "16.3.2", "react-dom": "16.3.2" }, "devDependencies": { "@microsoft/sp-build-web": "1.7.0", "@microsoft/sp-tslint-rules": "1.7.0", "@microsoft/sp-module-interfaces": "1.7.0", "@microsoft/sp-webpart-workbench": "1.7.0", "gulp": "~3.9.1", "@types/chai": "3.4.34", "@types/mocha": "2.2.38", "ajv": "~5.2.2" }

Please can you confirm what versions of React/Typescript/Office UI Fabric to use? Or any additional dependencies to install.

Thanks for your contribution! Sharing is caring.

pkbullock avatar Nov 12 '18 15:11 pkbullock

Thanks for your post, some SharePoint docs and examples are maintained by the community, so they will not be updated in real time. Welcome to submit any pull request for contribution.

Seiyasu avatar Nov 13 '18 03:11 Seiyasu

You have to use the latest Fabric 5 version. Fabric 6 is not working because SPFx 1.7 is comming with lower typescript version that the one needed in Fabric 6. I hope that in the next release of SPFx they will update typescript version to at least 2.8.

nmnikolov avatar Nov 13 '18 07:11 nmnikolov

@pkbullock could you add @uifabric/merge-styles into your package.json dependencies at 6.8.1, then try again?

cliffkoh avatar Nov 13 '18 09:11 cliffkoh

(There is another workaround to use the latest version of OUFR at version 6, but that is a very unideal workaround that opts out of type checking of OUFR. I'm reasonably confident that adding @uifabric/merge-styles@6.8.1 should unblock you however).

cliffkoh avatar Nov 13 '18 09:11 cliffkoh

I wouldn't try to use Fabric React v6 at this point... it hasn't been vetted for use within SPO at this time. Stick with v5.* for now.

Can you confirm which version of Fabric React you're using @pkbullock ?

To answer your question, I list the versions that v1.7 supports in my blog posts overview of 1.7 here. But to directly answer your questions on package versions:

  • TypeScript = 2.4.2
  • React & React DOM = v16.3.2
  • React type declarations = v16.4.2
  • React DOM type declarations = v16.0.5
  • Fabric React = v5.131.0

andrewconnell avatar Nov 14 '18 11:11 andrewconnell

Furthermore...

The documentation page for https://docs.microsoft.com/en-us/sharepoint/dev/spfx/office-ui-fabric-integration is quite far out of date. Can this be updated?

Can you specify what's outdated? LGTM... there's nothing that talks about installing a specific version of Fabric React. If you create a new React based project, you get exactly what you need & is supported (React, type declarations & Fabric React).

andrewconnell avatar Nov 14 '18 11:11 andrewconnell

@andrewconnell thanks for your comments, I found your post useful in understanding what has changed and what's missing.

In the documentation, under Office Fabric react, section: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/office-ui-fabric-integration#office-ui-fabric-react - "We recommend that you install the latest Office UI Fabric React package and place an explicit dependency on that specific version of the package"

I tried that, the latest repo is v6.130.1. I added it, it didn't work. So the package versions you have posted as super useful, its a shame the documentation doesn't include up to which supported version to use. I feel the article should include what is supported or tested by MS.

I noticed that @microsoft/[email protected] has "[email protected]" as a dependency, is that a better guide going forward to which version to use and is supported?

pkbullock avatar Nov 15 '18 09:11 pkbullock

Let me look into this... the way that doc you reference looks outdated as I don't think it should say that. You should use the version of Fabric React that's specified in a default SPFx project. That doc from my POV is only addressing OUIF, not Fabric React. I recognize it does reference Fabric React, but it shouldn't.

@VesaJuvonen @waldekmastykarz @estruyf - Does this doc look like it's making an incorrect statement? "We recommend that you install the latest Office UI Fabric React package and place an explicit dependency on that specific version of the package" That's no longer the case, right? We want people to use the version of Fabric React that is included in a SPFx project... correct?

I feel the article should include what is supported or tested by MS.

It does when you look at the doc that's specific to using Fabric React (https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/use-fabric-react-components#add-an-office-ui-fabric-component).

I think (if Vesa/Waldek/Elio confirm what I said above) we have a case of someone missing a doc when the guidance changed, as the doc you reference was last updated 11 months ago.

andrewconnell avatar Nov 15 '18 23:11 andrewconnell

@pkbullock confirmed w/ engineering the docs were incorrect in the link you referenced... my comment above is accurate & I just submitted a doc fix

andrewconnell avatar Nov 20 '18 13:11 andrewconnell

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 26 '20 00:01 msft-github-bot