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.js
anddist/xlsx.mini.min.js
files 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.json
pattern (should it be underimport
orrequire
or 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
exports
section 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.js
is registered in it for instance). Inside that object, theimport
key should reference the mjs version and therequire
key should reference the cjs version (it can be an UMD version as UMD supports being imported as CJS). Thetypes
key should probably reference a newmini.d.ts
file that would contain only the types for the mini API (theindex.d.ts
could then haveexport * from './mini.js'
instead of duplicating them all, with the node-only APIs staying inindex.d.ts
Starting 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.json
in theexports
field, and adding these lines tosrc/index.js
:The
require
equivalent 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
.js
extension)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 :