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

Package will not load if importing from @microsoft/sp-dialog

Open shaipetel opened this issue 3 years ago • 14 comments

Target SharePoint environment

SharePoint Online

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

💥 SharePoint Framework

Developer environment

Windows

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

  • browser version: latest
  • SPFx version: 1.16.1
  • Node.js version: 16
  • typescript version: 4.5.5
  • react 17.0.1
  • react-dom 17
  • removed @microsoft/office-ui-fabric-react-bundle package and used @fluentui/react 8.105.1

Describe the bug / error

When you add the following code anywhere in the SPFx package:

import { BaseDialog, IDialogConfiguration } from '@microsoft/sp-dialog';

and use that code in any way (so tree shaking doesn't remove it), the SPFx package will not be loaded on the browser. Instead you will get the following errors in the console:

  • Could not load [library name] in require. Trying in system.js
  • Could not load [library name] in require. Trying in system.js
  • Uncaught (in promise) Error
    • Trace shows its coming from "e.buildLoadComponentError"

and the code in the SPFx package will not execute on the page.

Steps to reproduce

for simplicity, this code doesn't do much except causes the project to blow up.

  1. Create a ListViewCommandSet component
  2. Add this code to the import:

import { Dialog } from '@microsoft/sp-dialog';

  1. add a new class at the end with a test dialog:
export default class TestDialog extends BaseDialog {
    public render(): void {
        ReactDOM.render(<h1>hello world!</h1>, this.domElement);
    }

    public getConfig(): IDialogConfiguration {
        return { isBlocking: false };
    }

    protected onAfterClose(): void {
        super.onAfterClose();

        // Clean up the element for the next dialog
        ReactDOM.unmountComponentAtNode(this.domElement);
    }
}
  1. In your command set onInit, add this code:
console.log("my project init");
console.dir(TestDialog);

Expected behavior

two messages would be written to the console.

shaipetel avatar Feb 06 '23 15:02 shaipetel

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

ghost avatar Feb 06 '23 15:02 ghost

The error message in console:

MicrosoftTeams-image (2)

shaipetel avatar Feb 06 '23 15:02 shaipetel

Hi, I'm also running into this issue, but I'm not using the dialog library.

image

AmonHouston avatar Feb 15 '23 22:02 AmonHouston

I'm also facing this issue. I tried removing the BaseDialog but it didn't solve it, maybe it has something to do with React or ReactDOM. Another thing I notice is that we are all facing this issue on a command set extension.

matteomessmer avatar Feb 16 '23 08:02 matteomessmer

Ran into similair issue where Dialog would render once then show blank afterwards.

Tried some different implementations and eventually updated our command set extension to use the FluentUI Dialog component: import { Dialog, DialogType } from 'office-ui-fabric-react/lib/Dialog';

Based on the implementation here: https://github.com/pnp/sp-dev-fx-extensions/tree/main/samples/react-command-convert-to-pdf/src/extensions/pdfExport

MattDev93 avatar Feb 16 '23 11:02 MattDev93

@MattDev93 it's not working for me

matteomessmer avatar Feb 16 '23 13:02 matteomessmer

Hi, could someone please verify this issue?

matteomessmer avatar Feb 20 '23 08:02 matteomessmer

@shaipetel were you able to solve this? I should develop an extension but I'm stuck

matteomessmer avatar Feb 24 '23 13:02 matteomessmer

I will say for me - I re-bundled and packaged my solution and then it decided to work. However I had already tried this numerous times before but it was the first time that day. So, it seems like it self-resolved or there was an issue on the MSFT server side that they fixed.

AmonHouston avatar Feb 26 '23 19:02 AmonHouston

Also not working for me

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

@paulcolucci I did install those versions and I think it may have worked. Thank you

matteomessmer avatar Mar 01 '23 15:03 matteomessmer

We need to change the documentation for the usage of dialogs. You need to explicitly install React as a dependency to create React components.

AJIXuMuK avatar Mar 01 '23 15:03 AJIXuMuK

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 08 '23 18:03 ghost