diff --git a/packages/loader/src/index.js b/packages/loader/src/index.js index 63dad52ff..c9bd3f75f 100644 --- a/packages/loader/src/index.js +++ b/packages/loader/src/index.js @@ -27,7 +27,7 @@ const requiredType = "javascript/auto"; export default function (source) { const options = loaderUtils.getOptions(this) || {} - if(isWebpack5) { + if(isWebpack5 && this._compilation) { const LoaderDependency = require("webpack/lib/dependencies/LoaderDependency"); const factory = this._compilation.dependencyFactories.get(LoaderDependency); if (factory === undefined) {