SharePoint / SharePoint/sp-dev-docs
SPFX loader is altering file extensions: .mjs file are transformed as ..js
@Ashlesha-MSFT is already working on this.
Since Mar 4, 2025.
- 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:
- clone https://github.com/stevebeauge/repro-spfx-mjs-cdn
pnpm installpnpm gulp serve- Open a workbench, add the
SpfxMjsCdnwebpart - The webpart loads
- In the dev console, you should see a console log like
PDFWorker, .... - generate the sppkg
pnpm run release - upload the sppkg file, deploy it
- add the related "application"
- Add the
SpfxMjsCdnon any page - The component does not load, trying to load the altered URL
Expected behavior
The public CDN shouldn't modify file extension
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.