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

"Cannot read properties of undefined (reading 'id')" when referencing ReactDOM from a ListViewCommandSet extension

Open dixonte opened this issue 3 years ago • 9 comments

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • [ ] 💥 Internet Explorer
  • [X] 💥 Microsoft Edge
  • [X] 💥 Google Chrome
  • [ ] 💥 FireFox
  • [ ] 💥 Safari
  • [ ] mobile (iOS/iPadOS)
  • [ ] mobile (Android)
  • [ ] not applicable
  • [ ] other (enter in the "Additional environment details" area below)

Additional environment details

  • Chrome v110.0.5481.104 / Edge 110.0.1587.57
  • SPFx v1.16.1
  • Node.js v16.19.1
  • @fluentui/react v8.105.11

Issue description

I want to create a new SPFX ListViewCommandSet button which opens a dialog box. This is something I did before back with SPFx 1.11.x. However, the moment I reference my custom dialog, the entire extension fails to load with the following error showing up in the console:

listview-host-assembly_en-us_22624d1282d23d4584d53bb10af184fb.js:68 Could not load hello-world-command-set in require. Trying in system.js. TypeError: Cannot read properties of undefined (reading 'id') at listview-host-assembly_en-us_22624d1282d23d4584d53bb10af184fb.js:68:360145 at new Promise (<anonymous>) at e.loadComponent (listview-host-assembly_en-us_22624d1282d23d4584d53bb10af184fb.js:68:360113) at listview-host-assembly_en-us_22624d1282d23d4584d53bb10af184fb.js:68:361874 at async Promise.all (/sites/TS20001/Shared%20Documents/Forms/index 1)

To try and make sure I hadn't done anything wrong, I created a new solution following the tutorial here: https://learn.microsoft.com/en-us/sharepoint/dev/spfx/extensions/guidance/using-custom-dialogs-with-spfx

And swapped from office-ui-fabric-react to @fluentui/react as suggested here: https://learn.microsoft.com/en-us/sharepoint/dev/spfx/release-1.16

I've also tried going through the code and commenting bits out until the extension loads. It looks like if I remove any reference to ReactDOM in ColorPickerDialog.tsx, the extension is able to load (albeit useless at that point).

Am I doing something wrong or is this a bug?

dixonte avatar Feb 27 '23 00:02 dixonte

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Feb 27 '23 00:02 ghost

I am also having the exact same issue

paulcolucci avatar Feb 27 '23 20:02 paulcolucci

it seems you need to explicitly install react and react-dom:

npm i [email protected] [email protected] @types/[email protected] @types/[email protected] --save-exact

paulcolucci avatar Feb 27 '23 20:02 paulcolucci

I can confirm this seems to fix the issue, though I get a bunch of warnings. I really should learn how to read this output but at the moment I can only guess that some other parts were pulling in react 17.0.2 instead of 17.0.1.

> npm i [email protected] [email protected] --save-exact

npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN   peer react@">=16.8.0 <19.0.0" from @fluentui/[email protected]
npm WARN   node_modules/@fluentui/foundation-legacy
npm WARN     @fluentui/foundation-legacy@"^8.2.29" from @fluentui/[email protected]
npm WARN     node_modules/@fluentui/react
npm WARN   25 more (@fluentui/react, @fluentui/react-compose, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"17.0.2" from [email protected]
npm WARN node_modules/react-dom
npm WARN   peer react-dom@">=16.8.0 <19.0.0" from @fluentui/[email protected]
npm WARN   node_modules/@fluentui/react
npm WARN   14 more (@fluentui/react-window-provider, @fluentui/theme, ...)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN   peer react@">=16.8.0 <19.0.0" from @fluentui/[email protected]
npm WARN   node_modules/@fluentui/foundation-legacy
npm WARN     @fluentui/foundation-legacy@"^8.2.29" from @fluentui/[email protected]
npm WARN     node_modules/@fluentui/react
npm WARN   25 more (@fluentui/react, @fluentui/react-compose, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"17.0.2" from [email protected]
npm WARN node_modules/react-dom
npm WARN   peer react-dom@">=16.8.0 <19.0.0" from @fluentui/[email protected]
npm WARN   node_modules/@fluentui/react
npm WARN   14 more (@fluentui/react-window-provider, @fluentui/theme, ...)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @rushstack/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   typescript@"~4.5.5" from @microsoft/[email protected]
npm WARN   node_modules/@microsoft/rush-stack-compiler-4.5
npm WARN     dev @microsoft/rush-stack-compiler-4.5@"^0.3.0" from the root project
npm WARN   3 more (@rushstack/eslint-config, tsutils, the root project)

dixonte avatar Feb 28 '23 02:02 dixonte

@dixonte - as stated by @paulcolucci - you need to explicitly install supported versions of React and ReactDOM. Also, currently SPFx is on Fluent UI v7, not v8. So if you have v8 explicitly in the package - please, consider downgrading.

AJIXuMuK avatar Mar 01 '23 15:03 AJIXuMuK

Thanks @AJIXuMuK. If it's not too much trouble, could you point me in the direction of some official documentation on what versions of packages I should be using with each version of SPFx? My own searching didn't turn anything up.

dixonte avatar Mar 02 '23 01:03 dixonte

@dixonte - here you go: https://learn.microsoft.com/en-us/sharepoint/dev/spfx/compatibility#spfx-development-environment-compatibility

AJIXuMuK avatar Mar 02 '23 01:03 AJIXuMuK

@AJIXuMuK Fantastic, thank you.

dixonte avatar Mar 02 '23 03:03 dixonte

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

ghost avatar Mar 09 '23 06:03 ghost