SharePoint / SharePoint/sp-dev-docs

SPFX loader is altering file extensions: .mjs file are transformed as ..js

Open
#10,106 9 comments 1 reaction 1 assignee View on GitHub

@Ashlesha-MSFT is already working on this.

Since Mar 4, 2025.

sharepoint-developer-support type:bug-confirmed type:bug-suspected
Dominant language
PowerShell
Stars
1.4k
Forks
1.1k
Avg merge
4d 12h
Merged PRs (30d)
12

Description

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
  • 💥 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
  • browser version : 132.0.2957.140 (Version officielle) (64 bits)
  • SPFx version : 1.20.0
  • Node.js version : 18.20.6
Describe the bug / error

Hi,

I've built a webpart that use pdfjs-dist library. The library is shipped as .mjs files.

Due to various reasons, I want this library to be marked as external in my package. I've set up the config.json file like this :

{
    "externals": {
        "pdfjs-dist": "node_modules/pdfjs-dist/build/pdf.min.mjs"
    }
}

Which is working in development mode (gulp serve).

I can see in my dist\<componentid>.manifest.json :

{

  "loaderConfig": {
    "scriptResources": {
    
      "pdfjs-dist": {
        "type": "path",
        "path": "pdfjs-dist_63b7d713cb9fdd2448e8f4d70e7bd228.mjs"
      }
    }
  }
}

Which is actually deployed into /clientsideassets of my target collection.

However, at run time (using production package), The component does not load.

I can see in the dev console a 404 error on this url: https://publiccdn.sharepointonline.com/mytenant.sharepoint.com/sites/mysite/ClientSideAssets/c503537f-b0a3-4609-8d9e-7cbbcd776982/pdfjs-dist_63b7d713cb9fdd2448e8f4d70e7bd228..js

If you look carefully, the extension in the CDN is not .mjs but ..js !

The CDN should preserve the exact file names.

Note that pdfjs-dist package is only an example, any mjs file should be kept as is

Steps to reproduce

I created a repro:

  1. clone https://github.com/stevebeauge/repro-spfx-mjs-cdn
  2. pnpm install
  3. pnpm gulp serve
  4. Open a workbench, add the SpfxMjsCdn webpart
  5. The webpart loads
  6. In the dev console, you should see a console log like PDFWorker, ....
  7. generate the sppkg pnpm run release
  8. upload the sppkg file, deploy it
  9. add the related "application"
  10. Add the SpfxMjsCdn on any page
  11. The component does not load, trying to load the altered URL
Expected behavior

The public CDN shouldn't modify file extension

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.