{"id":19416,"library":"copy-asset-in-memory-webpack-plugin","title":"copy-asset-in-memory-webpack-plugin","description":"Webpack 5 plugin to copy processed assets while the compilation is still in memory, before they are written to disk. Version 4.0.1 is the latest stable, with a history of breaking changes aligning with webpack 5. It allows filtering by test/include/exclude, renaming via `to`, transforming content, and optionally deleting original assets. Unlike copy-webpack-plugin which copies from filesystem to output, this plugin copies assets already in webpack's compilation graph. Requires webpack ^5.20.0 and Node >=12.13. Ships TypeScript types.","status":"active","version":"4.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/sibiraj-s/copy-asset-in-memory-webpack-plugin","tags":["javascript","webpack","webpack-plugin","copy-plugin","copy-webpack-plugin","copy-asset-in-memory-webpack-plugin","copy","typescript"],"install":[{"cmd":"npm install copy-asset-in-memory-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add copy-asset-in-memory-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add copy-asset-in-memory-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: requires webpack 5.20+","package":"webpack","optional":false}],"imports":[{"note":"This package does not export an ESM default; use CommonJS require in webpack config. For ESM usage, use dynamic import or convert config to .mjs with createRequire.","wrong":"import CopyAssetInMemoryPlugin from 'copy-asset-in-memory-webpack-plugin';","symbol":"CopyAssetInMemoryPlugin","correct":"const CopyAssetInMemoryPlugin = require('copy-asset-in-memory-webpack-plugin');"},{"note":"TypeScript types are exported as default: `export default class`. Named import fails in CJS because the only export is a default.","wrong":"const { CopyAssetInMemoryPlugin } = require('copy-asset-in-memory-webpack-plugin');","symbol":"CopyAssetInMemoryPlugin","correct":"import CopyAssetInMemoryPlugin from 'copy-asset-in-memory-webpack-plugin';"},{"note":"Options type is a named export in TypeScript. For value imports, use default. Type-only import avoids runtime errors.","wrong":"import { CopyAssetInMemoryPluginOptions } from 'copy-asset-in-memory-webpack-plugin';","symbol":"type CopyAssetInMemoryPluginOptions","correct":"import type { CopyAssetInMemoryPluginOptions } from 'copy-asset-in-memory-webpack-plugin';"}],"quickstart":{"code":"// webpack.config.js\nconst CopyAssetInMemoryPlugin = require('copy-asset-in-memory-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  plugins: [\n    new CopyAssetInMemoryPlugin({\n      test: /\\.js$/,\n      to: (fileName) => `scripts/${fileName}`,\n    }),\n  ],\n};","lang":"javascript","description":"Shows CommonJS usage in webpack.config.js, copying .js assets to a 'scripts' subfolder in memory."},"warnings":[{"fix":"Upgrade webpack to ^5.20.0. If stuck on webpack 4, use v3.x.","message":"v4.0.0 dropped support for webpack 4. Upgrade to webpack 5 to use this version.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Ensure the `to` option produces paths relative to the output directory. Do not use absolute paths or '..'.","message":"Assets cannot be copied outside the output directory. Attempting to do so will silently fail or cause undefined behavior.","severity":"gotcha","affected_versions":"*"},{"fix":"If you need source maps, either disable deleteOriginalAssets or manually copy the source map before deletion.","message":"deleteOriginalAssets: true deletes the asset's source map as well, because source maps are separate assets that share the same base filename.","severity":"gotcha","affected_versions":"*"},{"fix":"Explicitly set stage to Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL for forward compatibility.","message":"The `stage` option default is Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE. In future webpack versions, this stage might be removed or behave differently.","severity":"deprecated","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install -D copy-asset-in-memory-webpack-plugin` and ensure your webpack config is in a directory where node_modules can be resolved.","cause":"Package not installed or webpack config not resolving node_modules correctly.","error":"Cannot find module 'copy-asset-in-memory-webpack-plugin'"},{"fix":"Use `const CopyAssetInMemoryPlugin = require('copy-asset-in-memory-webpack-plugin');` in CommonJS, or `import CopyAssetInMemoryPlugin from 'copy-asset-in-memory-webpack-plugin';` in ESM (with appropriate configuration).","cause":"Incorrect import style; likely using ESM default import in a CJS context, or named import where default was expected.","error":"TypeError: CopyAssetInMemoryPlugin is not a constructor"},{"fix":"Use `Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE` (default) or another valid stage from webpack's Compilation object.","cause":"Invalid `stage` value; webpack removed or renamed the stage constant.","error":"Error: Hook is not defined for compilation stage"},{"fix":"Upgrade Node.js to version >=12.13.","cause":"Incompatible Node.js version installed (too low).","error":"Webpack 5 requires node >=10.13.0 but copy-asset-in-memory-webpack-plugin requires >=12.13"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}