The mini and core versions are not supported for usage with bundlers #2977
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#2977
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
dist/xlsx.core.min.jsanddist/xlsx.mini.min.jsfiles are not exposed in the package export, which means that bundlers support package exports (for instance webpack) will report them as non-existent.Side note: it would be great to have them in mjs format.
How can this be reproduced (e.g. what version of webpack) and what is the recommended
package.jsonpattern (should it be underimportorrequireor another key)?dist/xlsx.core.min.js, for example, is the rough equivalent of a glob import of the module script.PS: It feels like these packaging patterns change every year :(
Well, if you add the
exportssection in a package.json, any non-exported pattern becomes private. And this section has been added. That's why the packaging changes. You cannot do only half of the change...Good to know that core is equivalent in size to using the mjs version.
Regarding the mini version, it should be a new section (similar to how
./dist/cpexcel.jsis registered in it for instance). Inside that object, theimportkey should reference the mjs version and therequirekey should reference the cjs version (it can be an UMD version as UMD supports being imported as CJS). Thetypeskey should probably reference a newmini.d.tsfile that would contain only the types for the mini API (theindex.d.tscould then haveexport * from './mini.js'instead of duplicating them all, with the node-only APIs staying inindex.d.tsStarting with
./dist/xlsx.core.min.js, it looks like the following works when manually editing package.json in a project:This was tested by creating a small project based on the Webpack static asset demo, adding the aforementioned lines to
package.jsonin theexportsfield, and adding these lines tosrc/index.js:The
requireequivalent also appears to work:If manually making those changes works in your setup, we can add those blocks for each script (core / full / mini, with and without the
.jsextension)The 6 aliases have been added.
As a smoke test, the attached build throws unique error messages for each dist script and for the main/module scripts. Testing with the demo from https://docs.sheetjs.com/docs/demos/frontend/bundler#webpack :