speed-measure-webpack-plugin icon indicating copy to clipboard operation
speed-measure-webpack-plugin copied to clipboard

"You forgot to add 'mini-css-extract-plugin' plugin"

Open jalovatt opened this issue 4 years ago • 92 comments

Webpack 5 fails as soon as I smp.wrap() my config, with the following error:

ERROR in ..../Error.scss
Module build failed (from ../../node_modules/mini-css-extract-plugin/dist/loader.js):
Error: You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started
    at Object.pitch (.../node_modules/mini-css-extract-plugin/dist/loader.js:50:14)

The error stems from a missing symbol, which is defined when the plugin module loads, and assigned in a compilation hook:

// mini-css-extract-plugin/dist/loader.js@50
  if (!this[_index.pluginSymbol]) {
    callback(new Error("You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started"));
    return;
  }


// mini-css-extract-plugin/index.js@362
    compiler.hooks.compilation.tap(pluginName, compilation => {
      const normalModuleHook = typeof NormalModule.getCompilationHooks !== 'undefined' ? NormalModule.getCompilationHooks(compilation).loader : compilation.hooks.normalModuleLoader;
      normalModuleHook.tap(pluginName, loaderContext => {
        // eslint-disable-next-line no-param-reassign
        loaderContext[pluginSymbol] = true;
      });
    });

However, with smp.wrap() the inner callback above is never run and the symbol is never added to the loader's context.

Cheers. :)

Versions

webpack: 5.21.0
mini-css-extract-plugin: 1.3.9
speed-measure-webpack-plugin: 1.5.0

Config

plugins: [
  ...
  MiniCssExtractPlugin {
    _sortedModulesCache: WeakMap { <items unknown> },
    options: {
      filename: [Function: filename],
      ignoreOrder: false,
      chunkFilename: 'chunk-[name].[contenthash].css'
    },
    runtimeOptions: {
      insert: undefined,
      linkType: 'text/css',
      attributes: undefined
    }
  },
  ...
  SpeedMeasurePlugin {
    options: {},
    timeEventData: {},
    smpPluginAdded: true,
    wrap: [Function: bound wrap],
    getOutput: [Function: bound getOutput],
    addTimeEvent: [Function: bound addTimeEvent],
    apply: [Function: bound apply],
    provideLoaderTiming: [Function: bound provideLoaderTiming],
    generateLoadersBuildComparison: [Function: bound generateLoadersBuildComparison]
  }
],
module: {
  rules: [
    ...
    {
      test: /\.css$/,
      include: /node_modules/,
      use: [
        '.../node_modules/mini-css-extract-plugin/dist/loader.js',
        '.../node_modules/css-loader/dist/cjs.js'
      ]
    },
    {
      test: /\.(sass|scss|css)$/,
      exclude: /node_modules/,
      use: [
        '.../node_modules/mini-css-extract-plugin/dist/loader.js',
        {
          loader: '.../node_modules/css-loader/dist/cjs.js',
          options: { importLoaders: 1 }
        },
        {
          loader: '.../node_modules/sass-loader/dist/cjs.js',
          options: {
            implementation: {
              run_: [Function],
              render: [Function],
              renderSync: [Function],
              info: 'dart-sass\t1.23.0\t(Sass Compiler)\t[Dart]\n' +
                'dart2js\t2.5.1\t(Dart Compiler)\t[Dart]',
              types: [Object]
            },
            sassOptions: { fiber: false }
          }
        }
      ]
    }
  ]
}

jalovatt avatar Apr 03 '21 21:04 jalovatt

this same issues.

467057463 avatar Apr 06 '21 06:04 467057463

Same here

DunnJM avatar Apr 06 '21 15:04 DunnJM

+1

CKGrafico avatar Apr 12 '21 11:04 CKGrafico

same issue

vitalishapovalov avatar Apr 15 '21 10:04 vitalishapovalov

+1

doyakovlev avatar Apr 16 '21 14:04 doyakovlev

support webpack 5 ?

moyongshi avatar Apr 19 '21 11:04 moyongshi

any update on this?

nikkii94 avatar Apr 25 '21 10:04 nikkii94

Same question

getSpidd avatar Apr 26 '21 07:04 getSpidd

+1

zhouyupeng avatar Apr 30 '21 02:04 zhouyupeng

any updates there?

mbalc avatar May 11 '21 08:05 mbalc

+1

Ken-ding avatar May 16 '21 05:05 Ken-ding

+1

hardk-ngu avatar May 18 '21 02:05 hardk-ngu

+1

humingxian avatar May 25 '21 03:05 humingxian

any solution?

gentlecoder avatar May 31 '21 06:05 gentlecoder

+1

xikou1314 avatar Jun 02 '21 11:06 xikou1314

+1

andrei10k avatar Jun 04 '21 10:06 andrei10k

+1

2heal1 avatar Jun 06 '21 02:06 2heal1

+1

McDaddy avatar Jun 07 '21 02:06 McDaddy

Still happening with

 "webpack": "5.38.1",
 "mini-css-extract-plugin": "1.6.0",

I have the feeling this is an issue with the 'mini-css-extract-plugin' as this happens even without the 'speed-measure-webpack-plugin' installed.

D-Rosado avatar Jun 07 '21 14:06 D-Rosado

+1

zinge avatar Jun 07 '21 20:06 zinge

+1

wangjing013 avatar Jun 09 '21 08:06 wangjing013

I just downgraded mini-css-extract-plugin version to 1.3.6 https://github.com/webpack-contrib/mini-css-extract-plugin/releases/tag/v1.3.7 1.3.7 version cause this error.

taejs avatar Jun 17 '21 05:06 taejs

Not work with SpeedMeasurePlugin. I was deleted SpeedMeasurePlugin from my config and mini-css-extract-plugin work's fine

"dependencies": {
     "format-money-js": "^1.4.3",
     "selectivity": "^3.1.0",
     "spectre.css": "^0.5.9",
     "zepto-webpack": "^1.2.1"
 },
 "devDependencies": {
     "case-sensitive-paths-webpack-plugin": "^2.4.0",
     "circular-dependency-plugin": "^5.2.2",
     "css-loader": "^5.2.6",
     "expose-loader": "^3.0.0",
     "imports-loader": "^3.0.0",
     "inspectpack": "^4.7.1",
     "mini-css-extract-plugin": "^1.6.1",
     "node-sass": "^6.0.0",
     "purecss-sass": "^2.0.5",
     "sass-loader": "^11.1.1",
     "speed-measure-webpack-plugin": "^1.5.0",
     "style-loader": "^2.0.0",
     "unused-files-webpack-plugin": "^3.4.0",
     "webpack": "^5.37.1",
     "webpack-cli": "^4.7.0"
 }```
 

dejurin avatar Jun 28 '21 08:06 dejurin

same issue

mayunyi avatar Jul 01 '21 05:07 mayunyi

image image image Remove smp.wrap function run ok

mayunyi avatar Jul 01 '21 05:07 mayunyi

same issue, apart from lowering the version of mini-css-extract-plugin to 1.3.6, or remove smp.wrap(),

is there no other better solution that make smp and mini-css-extract-plugin use the latest version at the same time?

lanzhi-lee avatar Jul 13 '21 12:07 lanzhi-lee

same issue

lvxiaodi1234 avatar Jul 19 '21 12:07 lvxiaodi1234

+1

kryptonat avatar Jul 21 '21 01:07 kryptonat

+1

edouardmenayde avatar Jul 23 '21 14:07 edouardmenayde

I spent a little bit of time trying to debug this but haven't come up with anything conclusive. Here's some notes:

This plugin appears to produce a relevant deprecation warning:

(node:63005) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader

mini-css-extract-plugin throws the "You forgot to add..." error if it can't find Symbol(mini-css-extract-plugin) symbol in the loader context

https://github.com/webpack-contrib/mini-css-extract-plugin/blob/684ad366d2fc34e58746e687bb6d33a797c71be2/src/loader.js#L42-L51

This is set on the NormalModule compilation hook:

https://github.com/webpack-contrib/mini-css-extract-plugin/blob/684ad366d2fc34e58746e687bb6d33a797c71be2/src/index.js#L445-L457

Disabling wrapping for Compiler "fixes" the issue

https://github.com/stephencookdev/speed-measure-webpack-plugin/blob/ca66781752e4d11a0730a444b7c21947a569cd1b/WrappedPlugin/index.js#L162

const construcNamesToWrap = [
  // "Compiler",
  "Compilation",
  "MainTemplate",
  "Parser",
  "NormalModuleFactory",
  "ContextModuleFactory",
];

This hook never gets called when SMP is wrapping Compiler, so loaderContext[pluginSymbol] is never being set

https://github.com/webpack-contrib/mini-css-extract-plugin/blob/684ad366d2fc34e58746e687bb6d33a797c71be2/src/index.js#L453

That's about as far as I got, hopefully this is useful. I'm pretty unfamiliar with webpack internals so most of this is new to me so maybe somebody more familiar will be able to fix it from here.

stefan-toubia avatar Jul 27 '21 04:07 stefan-toubia