2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
									
										
										
										
											2023-10-16 09:12:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								title: Bun
							 
						 
					
						
							
								
									
										
										
										
											2022-08-24 23:48:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pagination_prev: getting-started/index
							 
						 
					
						
							
								
									
										
										
										
											2023-07-26 20:18:07 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pagination_next: getting-started/examples/index
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								sidebar_position: 7
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								sidebar_custom_props:
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  summary: Load NodeJS-style modules using CommonJS or ESM
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import current from '/version.js';
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import CodeBlock from '@theme/CodeBlock';
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Tarballs are available on < https: / / cdn . sheetjs . com > .
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< p > < a  href = {`https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz`} > https://cdn.sheetjs.com/xlsx-{current}/xlsx-{current}.tgz< / a >  is the URL for version {current}< / p >  
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 04:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::caution Bun support is considered experimental.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Great open source software grows with user tests and reports. Any issues should
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								be reported to the Bun project for further diagnosis.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Installation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Tarballs can be directly installed with `bun install` [^1]:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< CodeBlock  language = "bash" > {`\ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bun install https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz`}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-25 09:36:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::tip pass
							 
						 
					
						
							
								
									
										
										
										
											2023-04-27 09:12:19 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Watch the repo ](https://git.sheetjs.com/SheetJS/sheetjs ) or subscribe to the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[RSS feed ](https://git.sheetjs.com/sheetjs/sheetjs/tags.rss ) to be notified when
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								new versions are released!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::warning pass
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								At the time of writing `bun install`  does not support vendored tarballs[^2].
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Usage
  
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Bun supports both "CommonJS" and "ESM" modules.
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::info pass
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-24 03:59:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**It is strongly recommended to use CommonJS in Bun.**
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#### CommonJS `require`
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								By default, the module supports `require`  and it will automatically add support
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								for streams and file system access:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const { readFile } = require("xlsx");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const wb = readFile("pres.numbers"); // works!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#### ESM `import`
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								When importing the library using ESM `import`  statements, the native NodeJS
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								modules are not loaded. They must be added manually:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import * as XLSX from 'xlsx';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* load 'fs' for readFile and writeFile support */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import * as fs from 'fs';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XLSX.set_fs(fs);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* load 'stream' for stream support */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { Readable } from 'stream';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XLSX.stream.set_readable(Readable);
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* load the codepage support library for extended support with older formats  */
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import * as cpexcel from 'xlsx/dist/cpexcel.full.mjs';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XLSX.set_cptable(cpexcel);
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 23:59:44 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-16 09:12:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[^1]: Bun releases before the official 1.0.0 release did not support tarball dependencies. If a pre-1.0.0 release must be used, the [ES Module script can be vendored ](/docs/getting-started/installation/standalone#ecmascript-module-imports ) or the [NodeJS module can be installed with a NodeJS-compatible package manager ](/docs/getting-started/installation/nodejs ).
							 
						 
					
						
							
								
									
										
										
										
											2023-09-17 04:57:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[^2]: See [the relevant issue in the Bun issue tracker ](https://github.com/oven-sh/bun/issues/101 )