Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node v9 + Webpack v4 + extract-text-webpack-plugin = Compile Error

Tags:

webpack

//webpack.config.js -- shortened for convenience

const 
  ExtractTextPlugin = require("extract-text-webpack-plugin"),

  extractSass = new ExtractTextPlugin({
    filename: "Css/[name].css",
    allChunks: true
  }),

  //…
  config: {
    module: {
      rules: [
        //…
        {
          test: /\.scss$/,
          use: extractSass.extract([ 'css-loader', 'sass-loader' ])
        }
        //…
      ]

    },

    plugins: [
      extractSass
    ]
  }

  module.exports = config;

When used:

         0% compiling(node:333) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:333) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead                                                                                                                                                   
        77% module and chunk tree optimization unnamed compat plugin/xxx/node_modules/webpack/lib/Chunk.js:460
                throw new Error(
                ^

 Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
    at Chunk.get (/xxx/node_modules/webpack/lib/Chunk.js:460:9)
    at /xxx/node_modules/extract-text-webpack-plugin/dist/index.js:176:48
    at Array.forEach (<anonymous>)
    at /xxx/node_modules/extract-text-webpack-plugin/dist/index.js:171:18
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/xxx/node_modules/tapable/lib/Hook.js:35:21)
    at Compilation.seal (/xxx/node_modules/webpack/lib/Compilation.js:881:27)
    at hooks.make.callAsync.err (/xxx/node_modules/webpack/lib/Compiler.js:464:17)
    at _err0 (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)
    at _addModuleChain (/xxx/node_modules/webpack/lib/Compilation.js:749:12)
    at processModuleDependencies.err (/xxx/node_modules/webpack/lib/Compilation.js:688:9)
    at process._tickCallback (internal/process/next_tick.js:150:11)

That setup was working until webpack v4. Disabling the plugin makes the error disappear. I found that webpacks plugin system has changed, but I could not figure out how to fix that error.

like image 558
philipp Avatar asked Feb 26 '18 10:02

philipp


2 Answers

As described here, the Problem is that the extract-text-webpack-plugin needs to be upgraded in order to work with webpack v4. So:

npm install extract-text-webpack-plugin@next

will most certainly solve the problem.

like image 123
philipp Avatar answered Sep 20 '22 12:09

philipp


It appears that extract-text-webpack-plugin is deprecated for Webpack v4. See the README, which says:

⚠️ Since webpack v4 the extract-text-webpack-plugin should not be used for css. Use mini-css-extract-plugin instead.

This issue The Future of this Plugin vs. Mini CSS Extract Plugin provides more info about the deprecation.

like image 23
DoctorBud Avatar answered Sep 17 '22 12:09

DoctorBud