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

Class constructor h cannot be invoked without 'new'

Open jacksonv1lle opened this issue 7 months ago • 8 comments

Target SharePoint environment

SharePoint Online

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

💥 SharePoint Framework

Developer environment

None

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

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

Additional environment details

  • SPFx version: 1.20.2
  • Node.js version: 18.19.1

Describe the bug / error

We are seeing a tenant-specific regression affecting an SPFx library compiled with TypeScript target es5.

The bug presents with the following console error: TypeError: Class constructor h cannot be invoked without 'new' And causes the components that use custom extended versions of SPFx HTTP clients fail when they indirectly use MSGraphClientFactory or SPHttpClient.

For example we are implementing a custom class extending SPHttpClient like this:

export class SPHttpClientWithAuth extends SPHttpClient {
    constructor(serviceScope) {
        super(serviceScope);
    }
}

This is compiled as es5 and has been integrating fine with the SPHttpClient runtime code as that was also es5. Now that the runtime is es6, this class extend is failing.

Recompiling the library with target: es2015 resolves the issue.

We cannot find Microsoft documentation stating that ES5-compiled SPFx components are no longer supported, nor a published 2026 cutoff date for ES5 in SPFx.

Microsoft documentation still presents MSGraphClientV3 and SPHttpClient as supported SPFx APIs.

Steps to reproduce

  1. Configure an SPFx webpart with "target": "es5" in the tsconfig.json

  2. In the web part src directory, create a class which extends SPHttpClient

     export class CustomSPHttpClient extends SPHttpClient {
         public static serviceKey = ServiceKey.create<SPHttpClient>("CustomSPHttpClientService", this);
    
         constructor(serviceScope: ServiceScope){
             super(serviceScope);
         }
    
         protected async _fetch(url: string, configuration: SPHttpClientConfiguration, options: ISPHttpClientOptions): Promise<SPHttpClientResponse> {
             console.log("Fetch: ", url);
             return await super._fetch(url, configuration, options);
         }
     }
    
  3. Consume the CustomSPHttpClient service from the webpart.

  4. Deploy the web part on a tenant which uses es6 runtime

  5. Observe the error: TypeError: Class constructor h cannot be invoked without 'new'

Expected behavior

Please confirm whether Microsoft has recently changed the SharePoint Online/SPFx runtime, @microsoft/sp-http, MSGraphClientFactory, SPHttpClient, or related Graph client dependencies to require ES2015+ output. If this is intentional, please provide the official support/deprecation statement. If not, please treat this as a tenant-specific regression.

jacksonv1lle avatar Apr 27 '26 15:04 jacksonv1lle

Hello @jacksonv1lle, Thank you for bringing this issue to our attention. We will look into it and get back to you shortly.
If you don’t receive a reply within two working days, please use this escalation form to escalate.

Ashlesha-MSFT avatar Apr 28 '26 04:04 Ashlesha-MSFT

@jacksonv1lle, this behavior is understandable given the recent runtime changes, but it’s not a tenant-specific regression.

The error TypeError: Class constructor ... cannot be invoked without 'new' in this case is caused by a mismatch between the TypeScript compilation target (ES5) and the SharePoint Online runtime, which now includes native ES2015+ (ES6) classes (e.g., SPHttpClient, MSGraphClientFactory).

When targeting ES5, TypeScript transpiles class inheritance into function/prototype patterns that internally invoke the base class using .call(...). This is incompatible with native ES6 classes, which cannot be invoked as functions—only via new. As a result, extending SPFx classes like SPHttpClient from ES5-compiled code will fail at runtime.

This explains why:

  • Existing ES5 builds previously worked (when runtime was ES5-compatible)
  • The same code now fails in tenants where the runtime has been updated
  • Recompiling with "target": "es2015" resolves the issue

Recommendation

Update the tsconfig.json to target ES2015 or higher:


{
  "compilerOptions": {
    "target": "es2015"
  }
}

Aligning with ES2015+ ensures compatibility with the current SPFx runtime and avoids this inheritance issue.

Ashlesha-MSFT avatar Apr 28 '26 05:04 Ashlesha-MSFT

Hello @Ashlesha-MSFT and thank you for the information. I can't find any communication regarding these runtime changes and ES5 not being supported anymore. Could you please provide some MSFT documentation regarding this?

JulienVLC avatar Apr 28 '26 07:04 JulienVLC

Thanks for your response @Ashlesha-MSFT

Before we can roll out the fix, this is going to cause immediate breaking changes once the updated runtime is applied to our clients' tenants.

We have many clients using our product which will be affected by this sudden change to the runtime. Is there any documentation regarding this change or a strategy for how the changes are being deployed? It only seems to affect some of our tenants. Others are still receiving the es5 runtime.

jacksonv1lle avatar Apr 28 '26 07:04 jacksonv1lle

Hello @jacksonv1lle, thanks for the detailed information.

We’ve also reviewed the available SPFx documentation and release notes, but we could not find any official Microsoft statement explicitly documenting an ES5 deprecation or runtime change for SPFx.

We are currently checking this with the engineering team to confirm whether there has been a runtime change affecting SPFx class inheritance and if this is part of a staged rollout across tenants.

We’ll also request clarification on whether any official documentation exists or should be published for this behavior. We’ll update you as soon as we hear back.

Ashlesha-MSFT avatar Apr 28 '26 08:04 Ashlesha-MSFT

Thanks everyone for reporting this. SPFx has been backwards compatible since v1.0 and our intention is to keep this the case also in future. Our plan is not to require recompile existing solutions due any runtime changes as given the scale and usage of SPFx, that would be impossible for our customers worldwide.

We are actively now checking what to do here. I do apologize the situation and looking to provide an update as soon as possible.

VesaJuvonen avatar Apr 30 '26 07:04 VesaJuvonen

Thanks @VesaJuvonen. I understand it may be unconventional for us to extend the SPFx services like this. Would you recommend this approach? We are extending the SPHttpClient._fetch method to support requests across multi-GEO tenants. We are also extending the MSGraphClientFactory.getClient method to support CAE claims challenges

Consuming the services continues to work as normal regardless of ECMAScript versions, which is why it may have been missed.

jacksonv1lle avatar Apr 30 '26 08:04 jacksonv1lle

If anyone else is seeing this on top of @jacksonv1lle - please report your input here.

If you are extending other things in similar ways and are seeing issues - please add a comment.

We are trying to measure the worldwide impact of this - as it impacts our priorities. We are definitely looking into closely to fix this.

VesaJuvonen avatar Apr 30 '26 16:04 VesaJuvonen