webpack-xlsx-loader

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript deprecated

Webpack loader that imports and parses .xlsx files into a workbook object compatible with the xlsx npm module. Version 1.0.0 is the initial release with no active development since 2016. It transforms xlsx files into a JSON representation (SheetNames and Sheets) that can be directly consumed by xlsx utility functions. Differentiated by simplicity: just a loader with no extra configuration required. Alternatives include raw xlsx import with file-loader or manual parsing.

error Module parse failed: Unexpected token (1:0) in file.xlsx
cause Webpack doesn't have a loader for .xlsx files.
fix
Add webpack-xlsx-loader to webpack config as shown in usage.
error Cannot find module 'xlsx'
cause xlsx is not installed.
fix
Run npm install xlsx.
error Spreadsheet import is undefined
cause The loader output is a JSON object; must be default imported.
fix
Use import spreadsheet from './file.xlsx' not import { SheetNames } from './file.xlsx'.
deprecated No updates since 2016; not compatible with webpack 5+ (deprecated loader API).
fix Use a modern replacement like @softarc/xlsx-loader or raw xlsx with asset modules.
gotcha Requires xlsx as a peer dependency; not automatically installed.
fix Run npm install xlsx separately.
breaking Webpack 4 loader API changes: pitch phase may break with extract-text-webpack-plugin.
fix Use MiniCssExtractPlugin or avoid loaders that intercept pitch.
npm install webpack-xlsx-loader
yarn add webpack-xlsx-loader
pnpm add webpack-xlsx-loader

Configures webpack to load xlsx files, then imports a spreadsheet and converts first sheet to CSV.

// webpack.config.js
module.exports = {
  module: {
    rules: [
      { test: /\.xlsx$/, loader: 'webpack-xlsx-loader' }
    ]
  }
};

// app.js
import spreadsheet from './data.xlsx';
import xlsx from 'xlsx';

console.log(spreadsheet.SheetNames); // ['Sheet1']
console.log(xlsx.utils.sheet_to_csv(spreadsheet.Sheets['Sheet1']));