{"id":19466,"library":"emit-file-webpack-plugin","title":"emit-file-webpack-plugin","description":"Webpack plugin to emit arbitrary files into the compilation output. Current stable version is 2.0.1, released in 2023. Low release cadence. Differentiator: handles async content, hash injection, and custom output paths without extra dependencies like copy-webpack-plugin. Ships TypeScript declarations. Requires webpack and webpack-sources as peer dependencies.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/Kir-Antipov/emit-file-webpack-plugin","tags":["javascript","webpack","plugin","create","file","emit","copy","generate","typescript"],"install":[{"cmd":"npm install emit-file-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add emit-file-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add emit-file-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; the plugin interfaces with webpack's compilation hooks.","package":"webpack","optional":false},{"reason":"Peer dependency; used for creating source map–aware assets.","package":"webpack-sources","optional":false}],"imports":[{"note":"Default export; in CommonJS you can use require() directly without .default.","wrong":"const EmitFilePlugin = require('emit-file-webpack-plugin').default","symbol":"EmitFilePlugin","correct":"import EmitFilePlugin from 'emit-file-webpack-plugin'"},{"note":"Named export is not available in CJS; only default export exists.","wrong":"const EmitFilePlugin = require('emit-file-webpack-plugin').EmitFilePlugin","symbol":"EmitFilePlugin","correct":"const { EmitFilePlugin } = require('emit-file-webpack-plugin')"},{"note":"Named import is incorrect; the package provides a default export only.","wrong":"import { EmitFilePlugin } from 'emit-file-webpack-plugin'","symbol":"EmitFilePlugin","correct":"import EmitFilePlugin from 'emit-file-webpack-plugin'"}],"quickstart":{"code":"const EmitFilePlugin = require('emit-file-webpack-plugin');\n\nmodule.exports = {\n  // ... other webpack config\n  plugins: [\n    new EmitFilePlugin({\n      filename: 'version.json',\n      content: JSON.stringify({ version: process.env.npm_package_version || '0.0.0' })\n    })\n  ]\n};","lang":"javascript","description":"Shows basic usage using CommonJS require with a JSON output file."},"warnings":[{"fix":"If you need JSON.stringify, use JSON.stringify(content) explicitly in the content option.","message":"In v2.0.0, the plugin now respects overridden .toString() on content objects. Previously, non-string/non-buffer content would always be JSON.stringify'd. If your content object overrides toString but you relied on JSON.stringify behavior, this change may break your output.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Always use absolute paths with path.resolve() to avoid confusion.","message":"The 'path' option can be relative to webpack's output path or absolute. If you specify a relative path, it's resolved from webpack's output.path, not from the project root.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Install webpack-sources: npm install --save-dev webpack-sources","message":"Webpack 5 removed the require('webpack-sources'); you must install webpack-sources as a separate peer dependency. The plugin does not bundle it.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Explicitly add '[hash]' in the filename to control placement, e.g., 'index.[hash].js'.","message":"If you use the 'hash' option, and you don't include '[hash]' in the filename, the hash will be appended as a query string (e.g., index.js?hash). This may not work for all asset types (e.g., images in CSS).","severity":"gotcha","affected_versions":">=1.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install peer dependencies: npm install --save-dev webpack webpack-sources","cause":"Missing or incompatible webpack and webpack-sources peer dependencies.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Use default import: import EmitFilePlugin from 'emit-file-webpack-plugin' or const EmitFilePlugin = require('emit-file-webpack-plugin').","cause":"Incorrect import of the plugin (named import instead of default).","error":"Error: Couldn't find plugin with the id \"EmitFilePlugin\""},{"fix":"Upgrade to webpack 5 or use an older version of the plugin that supports webpack 4.","cause":"Using the plugin with webpack 4 or older, where processAssets hook does not exist.","error":"TypeError: compilation.hooks.processAssets is not a function","affected_versions":">=2.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}