4.7 KiB
| title | sidebar_label | pagination_prev | pagination_next | sidebar_custom_props | ||
|---|---|---|---|---|---|---|
| Packing Sheets with pkg | pkg | demos/desktop/index | demos/data/index |
|
import current from '/version.js'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import CodeBlock from '@theme/CodeBlock';
export const r = {style: {color:"red"}}; export const B = {style: {fontWeight:"bold"}};
pkg1 is a tool for generating command-line tools that embed scripts.
SheetJS is a JavaScript library for reading and writing data from spreadsheets.
This demo uses pkg and SheetJS to create a standalone CLI tool for parsing
spreadsheets and converting to other formats.
:::caution pass
With the official release of NodeJS SEA, Vercel opted
to deprecate pkg. It is still useful for deploying apps with NodeJS version 18
or earlier since those versions do not support NodeJS SEA.
:::
:::note Tested Deployments
This demo was tested in the following deployments:
| Architecture | Version | NodeJS | Date |
|---|---|---|---|
darwin-x64 |
5.8.1 |
18.5.0 |
2025-04-21 |
darwin-arm |
5.8.1 |
18.5.0 |
2025-06-18 |
win11-x64 |
5.8.1 |
18.5.0 |
2025-05-07 |
win11-arm |
5.8.1 |
18.5.0 |
2025-02-23 |
linux-x64 |
5.8.1 |
18.5.0 |
2025-04-21 |
linux-arm |
5.8.1 |
18.5.0 |
2025-02-15 |
:::
:::caution pass
pkg on Windows on ARM uses the X64 compatibility layer. It does not generate
a native ARM64 binary!
:::
Integration Details
The SheetJS NodeJS module can be
required from scripts. pkg will automatically handle packaging.
Script Requirements
Scripts that exclusively use SheetJS libraries and NodeJS built-in modules can
be bundled using pkg.
The demo script xlsx-cli.js runs in NodeJS. It
is a simple command-line tool for reading and writing spreadsheets.
Limitations
:::danger pass
When this demo was last tested, pkg failed with an error referencing node20:
> Targets not specified. Assuming:
node20-linux-arm64, node20-macos-arm64, node20-win-arm64
> Error! No available node version satisfies 'node20'
pkg does not support NodeJS 20 or 22 or 24!
The local NodeJS version must be rolled back to version 18.
If nvm or nvm-windows was used to install NodeJS:
nvm install 18
nvm use 18
Otherwise, on macOS and Linux, n can manage the global installation:
sudo npm i -g n
sudo n 18
On Windows, it is recommended to use a prebuilt installer2
:::
Complete Example
-
Downgrade NodeJS to major version 18 or earlier.
-
Download the test file https://docs.sheetjs.com/pres.numbers:
curl -o pres.numbers https://docs.sheetjs.com/pres.numbers
- Download
xlsx-cli.js
curl -o xlsx-cli.js https://docs.sheetjs.com/cli/xlsx-cli.js
- Install the dependencies:
- Create the standalone program:
npx -y pkg xlsx-cli.js
This generates xlsx-cli-linux, xlsx-cli-macos, and xlsx-cli-win.exe .
:::info pass
If it is not possible to switch NodeJS versions, the -t flag can be used to
override the target detection:
X64
npx -y pkg -t 'node18-win-x64,node18-linux-x64,node18-macos-x64' xlsx-cli.js
ARM64
npx -y pkg -t 'node18-win-arm64,node18-linux-arm64,node18-macos-arm64' xlsx-cli.js
:::
- Run the generated program, passing
pres.numbersas the argument:
./xlsx-cli-linux pres.numbers
./xlsx-cli-macos pres.numbers
.\xlsx-cli-win.exe pres.numbers
-
The project does not have a website. The source repository is publicly available. ↩︎
-
The NodeJS website hosts prebuilt installers. ↩︎