add exports field to package.json #2744
No reviewers
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#2744
Loading…
Reference in New Issue
No description provided.
Delete Branch "exports-field-package"
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?
What tools or platforms are affected by the change?
Running into an issue using SheetJS with vite: https://github.com/vitejs/vite/discussions/9149
Vite is using the CJS distribution of SheetJS and is incorrectly converting that to ESM. This config change will allow Vite to use the ESM distribution of SheetJS directly.
The last time we seriously looked into modules / ESM support, tooling looked for the
module
field in package.json. This sufficed:If Vite requires something extra, changes can be made as long as they don't break older NodeJS versions or other bundlers.
There are two changes here:
type: "module"
andexports
.Based on the NodeJS docs,
type: "module"
affects interpretations of.js
files, but there is no confusion here: the.js
files are CommonJS and the.mjs
files are ESM.With the goal of persuading Vite to use
xlsx.mjs
when importing, would theexports
field suffice (is"type": "module"
also needed)?I got that off the Vite docs which recommends the following for libraries:
https://vitejs.dev/guide/build.html#library-mode
After reading the NodeJS docs,
type: module
isn't useful here if the source code isn't written in esm and if it isn't meant to be directly used (?). I'll update the PR.We pushed 0.18.10 (mainly to make sure that the package.json changes worked)
Does it work in your testing with Vite?
Yep, thanks for the quick resolution 🤗.