{"id":18564,"library":"mocha-webpack","title":"mocha-webpack","description":"A CLI tool that integrates Mocha test runner with Webpack bundling, allowing you to test modules that rely on Webpack features (loaders, plugins, resolve aliases) without pre-building or using hacks. Version 1.1.0 is the latest stable release (as of late 2018). It supports Mocha >=2.4.5 <=5 and Webpack 2.x/3.x. Key differentiators: bundling tests into a single bundle with Webpack's full pipeline (loaders, resolve, plugins), built-in source map support, memory-fs for speed (no disk writes), customizable file watcher, and support for multiple entry files/patterns. The project is effectively unmaintained (last release 2017) for Webpack 4+ compatibility.","status":"deprecated","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/zinserjan/mocha-webpack","tags":["javascript","webpack","mocha"],"install":[{"cmd":"npm install mocha-webpack","lang":"bash","label":"npm"},{"cmd":"yarn add mocha-webpack","lang":"bash","label":"yarn"},{"cmd":"pnpm add mocha-webpack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: test runner framework","package":"mocha","optional":false},{"reason":"peer dependency: module bundler for test compilation","package":"webpack","optional":false}],"imports":[{"note":"mocha-webpack includes source-map-support by default since v1.0.0. CLI usage only; no programmatic API exported.","wrong":"mocha-webpack --require source-map-support/register test/**/*.spec.js","symbol":"mocha-webpack","correct":"npx mocha-webpack --webpack-config webpack.config.js test/**/*.spec.js"},{"note":"mocha-webpack does not export any functions or objects; requiring it merely registers the CLI command. Use CLI arguments instead.","wrong":"const { run } = require('mocha-webpack');","symbol":"mocha-webpack (require from Node)","correct":"import 'mocha-webpack'; // or require('mocha-webpack') — only side effects"}],"quickstart":{"code":"// package.json scripts\n{\n  \"scripts\": {\n    \"test\": \"mocha-webpack --webpack-config webpack.test.js --opts ./mocha-webpack.opts test/**/*.spec.js\"\n  }\n}\n// mocha-webpack.opts\n--timeout 10000\n--reporter spec\n// webpack.test.js (example)\nconst path = require('path');\nmodule.exports = {\n  mode: 'development',\n  resolve: {\n    extensions: ['.js', '.jsx', '.json']\n  },\n  module: {\n    rules: [\n      {\n        test: /\\.jsx?$/,\n        exclude: /node_modules/,\n        use: {\n          loader: 'babel-loader',\n          options: { presets: ['@babel/preset-env', '@babel/preset-react'] }\n        }\n      }\n    ]\n  }\n};\n// Run: npx mocha-webpack --webpack-config webpack.test.js test/**/*.spec.js","lang":"javascript","description":"Configures mocha-webpack with a webpack config file, custom opts file, and runs tests matching a glob pattern."},"warnings":[{"fix":"Migrate to mochapack (https://github.com/sysgears/mochapack) or configure webpack+mocha manually.","message":"mocha-webpack is unmaintained since v1.1.0 (2017). No Webpack 4/5 compatibility. Use mochapack or webpack-shell-plugin instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Remove any references to generated bundle file. Use --webpack-config to specify output settings or rely on memory-fs.","message":"v1.0.0 switched from writing bundle to disk to using memory-fs. If you relied on the generated bundle file, it no longer exists.","severity":"breaking","affected_versions":">=1.0.0 <1.0.0"},{"fix":"Ensure webpack resolve.extensions includes '.js' and other extensions used in your tests.","message":"v1.0.0 replaced 'glob-like' file resolution with real glob. Patterns like 'test/unit/*' may resolve differently if `resolve.extensions` not set.","severity":"breaking","affected_versions":">=1.0.0 <1.0.0"},{"fix":"Omit `entry` and `output` from your webpack test config, or use `--webpack-config` that merges partial configs.","message":"mocha-webpack will ignore webpack's `entry` and `output` configuration; it overrides them internally. Do not set them in your webpack config, or they will be overwritten.","severity":"gotcha","affected_versions":"*"},{"fix":"Use webpack@3.x or switch to mochapack (supports webpack 4+).","message":"Webpack 4 is not supported. Attempting to use mocha-webpack with webpack@4 will fail at module resolution.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Rename your opts file to `mocha-webpack.opts` or use `--opts path/to/your.opts`.","message":"The `--opts` flag defaults to looking for `mocha-webpack.opts` or `mocha.opts` in the current directory. If you have both, mocha-webpack prefers `mocha-webpack.opts`.","severity":"deprecated","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install mocha-webpack locally: `npm install --save-dev mocha-webpack` and use npx or package.json scripts.","cause":"Mocha-webpack is not installed globally or locally when running via CLI.","error":"Error: Cannot find module 'mocha-webpack' from '<PROJECT>'\n    at Function.module.exports [as runMain] (module.js:xxx:xx)"},{"fix":"Downgrade to webpack@3 or migrate to mochapack.","cause":"Using mocha-webpack with webpack 4, which removed deprecated plugins.","error":"Error: webpack.optimize.OccurrenceOrderPlugin is not a constructor"},{"fix":"Update to mocha-webpack@1.1.0 which fixed this bug.","cause":"This error appears in v1.0.1 and was fixed; related to file resolution issues.","error":"TypeError: Cannot read property 'getFiles' of undefined"},{"fix":"Set webpack target to 'node' in your webpack config: `target: 'node'`.","cause":"Webpack target/node misconfiguration; mocha-webpack expects Node environment.","error":"Error: Module not found: Error: Can't resolve 'fs' in '<PROJECT>/node_modules/mocha-webpack'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}