Copy-webpack-plugin: compilation.getLogger is not a function

Created on 11 Jun 2020  路  7Comments  路  Source: webpack-contrib/copy-webpack-plugin

  • Operating System: macOS 10.15.5
  • Node Version: 13.1.0
  • NPM Version: 6.12.1
  • webpack Version: 4.31.0 (using webpacker gem)
  • copy-webpack-plugin Version: 6.0.2

Expected Behavior

I expect the plugin to be loaded

Actual Behavior

Throws the following error during:

ers/stephen.turley/Projects/myProject/node_modules/copy-webpack-plugin/dist/index.js:38
        const logger = compilation.getLogger('copy-webpack-plugin');
                                   ^

  TypeError: compilation.getLogger is not a function
      at /Users/stephen.turley/Projects/myProject/node_modules/copy-webpack-plugin/dist/index.js:38:34
>>    at SyncHook.eval [as call] (eval at create (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:5:1  )
      at SyncHook.lazyCompileHook (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/Hook.js:154:20)
      at Compiler.newCompilation (/Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:581:26)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:617:29
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <an  onymous>:4:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/Hook.js:154:20)
      at Compiler.compile (/Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:612:28)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:284:11
      at Compiler.readRecords (/Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:479:11)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:281:10
      at eval (eval at create (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/CachePlugin.js:52:13
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <an  onymous>:5:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/Hook.js:154:20)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:278:19
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <an  onymous>:13:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/stephen.turley/Projects/myProject/node_modules/tapable/lib/Hook.js:154:20)
      at Compiler.run (/Users/stephen.turley/Projects/myProject/node_modules/webpack/lib/Compiler.js:275:24)
      at processOptions (/Users/stephen.turley/Projects/myProject/node_modules/webpack-cli/bin/cli.js:362:14)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack-cli/bin/cli.js:373:3
      at Object.parse (/Users/stephen.turley/Projects/myProject/node_modules/yargs/yargs.js:567:18)
      at /Users/stephen.turley/Projects/myProject/node_modules/webpack-cli/bin/cli.js:49:8
      at Object.<anonymous> (/Users/stephen.turley/Projects/myProject/node_modules/webpack-cli/bin/cli.js:375:3)
      at Module._compile (internal/modules/cjs/loader.js:1063:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
      at Module.load (internal/modules/cjs/loader.js:914:32)
      at Function.Module._load (internal/modules/cjs/loader.js:822:14)
      at Module.require (internal/modules/cjs/loader.js:956:19)
      at require (internal/modules/cjs/helpers.js:74:18)
      at Object.<anonymous> (/Users/stephen.turley/Projects/myProject/node_modules/webpack/bin/webpack.js:156:2)
      at Module._compile (internal/modules/cjs/loader.js:1063:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
      at Module.load (internal/modules/cjs/loader.js:914:32)
      at Function.Module._load (internal/modules/cjs/loader.js:822:14)
      at Function.Module.runMain (internal/modules/cjs/loader.js:1143:12)

Code

config/webpack/copy.js

const CopyPlugin = require('copy-webpack-plugin')

  const filesToCopy = [
    {
      from: './node_modules/pspdfkit/dist/pspdfkit-lib',
      to: './pspdfkit-lib'
    }
  ]

  module.exports = {
    plugins: [
      new CopyPlugin({patterns: filesToCopy})
    ]
  }


config/webpack/environment.js

const { environment } = require('@rails/webpacker')
  const copyPlugin = require('./copy');

  environment.config.merge(copyPlugin);

  module.exports = environment


~

How Do We Reproduce?

I'm using the webpacker gem as part of a ruby on rails project. With the configuration above, I run bin/webpack and get the listed error.

I'm not sure if this is a webpacker thing, or I'm a noob at webpack thing. Forgive me if this is not a bug, but I've spent a few hours and a few variations of the config above trying to fix it.

Most helpful comment

@evilebottnawi updating webpack to the latest version usually involves a refactor of the entire webpack configuration pipeline.

If you're lightweight user of webpack, or you have hours to waste everytime this happens you might feel this is a feasible option...

But for those of us in the real world it is not.

All 7 comments

So, downgrading to 5.1.1 and using the old constructor fixes the issue for me.

Update webpack version https://github.com/webpack-contrib/copy-webpack-plugin/blob/master/package.json#L41 and never ignore warnings/errors from npm/yarn

me too

@evilebottnawi updating webpack to the latest version usually involves a refactor of the entire webpack configuration pipeline.

If you're lightweight user of webpack, or you have hours to waste everytime this happens you might feel this is a feasible option...

But for those of us in the real world it is not.

@airtonix no big breaking change, migration is very easy

For the record, updating to 4.44 fixed this for me, didn't need to upgrade to the major version.

@dewezlopez I can confirm that upgrading webpack to 4.44.0 and downgrading copy-webpack-plugin to 6.2.1 works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickenchev picture nickenchev  路  3Comments

dmarcautan picture dmarcautan  路  5Comments

richmeij picture richmeij  路  5Comments

RPDeshaies picture RPDeshaies  路  5Comments

ietabhi picture ietabhi  路  5Comments