webpack-utf8-bom
raw JSON → 1.4.0 verified Sat Apr 25 auth: no javascript
Webpack plugin to add or remove UTF-8 BOM (Byte Order Mark) from output files. Current stable version is 1.4.0, supporting both webpack 4 and 5. Lightweight plugin with a single configuration option (boolean). Differentiator: focused solely on BOM manipulation; alternatives may require custom loaders or post-processing.
Common errors
error Error: Cannot find module 'webpack-utf8-bom' ↓
cause Package not installed in node_modules.
fix
Run npm install webpack-utf8-bom --save-dev
error TypeError: BomPlugin is not a constructor ↓
cause Incorrect import: using import statement or destructuring without default.
fix
Use const BomPlugin = require('webpack-utf8-bom');
error BomPlugin is not a function ↓
cause Trying to use plugin without new keyword.
fix
Add new: new BomPlugin(true)
Warnings
breaking Webpack 5 support was added in v1.3.0. v1.4.0 and later require webpack 4.x.x or 5.x.x. ↓
fix Use at least v1.3.0 for webpack 5 compatibility.
gotcha Plugin constructor expects a boolean, not an object. Passing an object will be coerced to true (truthy) and may not behave as expected. ↓
fix Pass a boolean value: new BomPlugin(true) or new BomPlugin(false).
gotcha The plugin modifies output files after compilation. It does not affect source maps unless explicitly configured. ↓
fix If you need source maps with BOM, ensure source maps are generated and the BOM plugin runs after.
Install
npm install webpack-utf8-bom yarn add webpack-utf8-bom pnpm add webpack-utf8-bom Imports
- webpack-utf8-bom wrong
import BomPlugin from 'webpack-utf8-bom';correctconst BomPlugin = require('webpack-utf8-bom'); - BomPlugin wrong
new BomPlugin({ addBOM: true }) or similar object argumentcorrectnew BomPlugin(true)
Quickstart
const BomPlugin = require('webpack-utf8-bom');
module.exports = {
entry: './src/index.js',
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
},
plugins: [
new BomPlugin(true) // Adds UTF-8 BOM to output
]
};