webpack/webpack · error · Error

module property was removed from Dependency (use compilation

Error message

module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)

What it means

The `dependency.module` setter was removed alongside the getter (webpack 5): dependencies are immutable graph nodes and the link to their target module is managed by the module graph, not by assigning on the dependency. The throwing setter prevents old code from silently no-op'ing while believing it changed the graph.

Source

Thrown at lib/Dependency.js:492

Object.defineProperty(Dependency.prototype, "module", {
	/**
	 * Returns throws.
	 * @deprecated
	 * @returns {EXPECTED_ANY} throws
	 */
	get() {
		throw new Error(
			"module property was removed from Dependency (use compilation.moduleGraph.getModule(dependency) instead)"
		);
	},

	/**
	 * Updates module.
	 * @deprecated
	 * @returns {never} throws
	 */
	set() {
		throw new Error(
			"module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)"
		);
	}
});

/**
 * Returns true if the dependency is a low priority dependency.
 * @param {Dependency} dependency dep
 * @returns {boolean} true if the dependency is a low priority dependency
 */
Dependency.isLowPriorityDependency = (dependency) =>
	/** @type {ModuleDependency} */ (dependency).sourceOrder === Infinity;

// TODO in webpack 6, call canConcatenate() directly on the dependency instance instead of using this static method.
/**
 * Returns true if the dependency can be concatenated (scope hoisting).
 * @param {Dependency} dependency dep
 * @param {boolean} concatenateCommonJsModules whether optimization.concatenateModules.commonjs is enabled

View on GitHub (pinned to 318421ea8a)

Solutions

  1. Replace `dependency.module = m` with `compilation.moduleGraph.updateModule(dependency, m)`.
  2. If you are creating a new edge, add a new dependency and wire it through the module graph rather than mutating an existing one.
  3. Review custom Dependency subclasses for constructor-time `this.module =` assignments (also invalid).

Example fix

// before
dependency.module = newModule;

// after
compilation.moduleGraph.updateModule(dependency, newModule);
Defensive patterns

Strategy: validation

Validate before calling

function retarget(compilation, dependency, module) {
  // Never assign dependency.module = ...; update via the graph.
  compilation.moduleGraph.updateModule(dependency, module);
}

Prevention

When it happens

Trigger: Assigning `dependency.module = someModule` in plugin or custom-dependency code. Appears in webpack 4 plugins that rewired a dependency's target at build time.

Common situations: Plugins that dynamically retarget imports (e.g. redirecting a require to a different module) by mutating the dependency. Migration of mutation-heavy webpack 4 plugins.

Related errors


AI-assisted analysis of webpack/webpack@318421ea8a (2026-08-03). Data as JSON: /data/errors/16bdcb79744a1175.json. Report an issue: GitHub.