Copy-webpack-plugin causes build failure on netlify

Describe the bug

Adding copy-webpack-plugin causes build failure in netlify.
They use import() to load ESM dependencies, looks like your env is not supported it

When I run build on my local machine or even in gitlab ci pipeline everything worked fine.

Steps to reproduce

When running webpack build, it fails on:
8:55:20 PM: $ npm run build
8:55:20 PM: > webpack-test@1.0.0 build /opt/build/repo
8:55:20 PM: > webpack --mode production
8:55:31 PM: (node:3235) ExperimentalWarning: The ESM module loader is experimental.
8:55:31 PM: [webpack-cli] HookWebpackError: Only file and data URLs are supported by the default ESM loader
8:55:31 PM: at makeWebpackError (/opt/build/repo/node_modules/webpack/lib/HookWebpackError.js:48:9)
8:55:31 PM: at /opt/build/repo/node_modules/webpack/lib/Compilation.js:3059:12
8:55:31 PM: at eval (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCodeFactory.js:33:10), :78:1)
8:55:31 PM: at /opt/build/repo/node_modules/webpack/lib/Compilation.js:510:26
8:55:31 PM: at /opt/build/repo/node_modules/copy-webpack-plugin/dist/index.js:708:13
8:55:31 PM: -- inner error --
8:55:31 PM: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
8:55:31 PM: at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:720:11)
8:55:31 PM: at Loader.resolve (internal/modules/esm/loader.js:97:40)
8:55:31 PM: at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
8:55:31 PM: at ModuleWrap. (internal/modules/esm/module_job.js:42:40)
8:55:31 PM: at link (internal/modules/esm/module_job.js:41:36)
8:55:31 PM: caused by plugins in Compilation.hooks.processAssets
8:55:31 PM: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
8:55:31 PM: at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:720:11)
8:55:31 PM: at Loader.resolve (internal/modules/esm/loader.js:97:40)
8:55:31 PM: at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
8:55:31 PM: at ModuleWrap. (internal/modules/esm/module_job.js:42:40)
8:55:31 PM: at link (internal/modules/esm/module_job.js:41:36)

Environment

System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
Memory: 17.37 GB / 31.78 GB
Binaries:
Node: 14.17.4 - C:\Program Files\nodejs\node.EXE
npm: 6.14.14 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.36)
Internet Explorer: 11.0.19041.1566
Packages:
babel-loader: ^8.2.4 => 8.2.4
clean-webpack-plugin: ^4.0.0 => 4.0.0
css-loader: ^6.7.1 => 6.7.1
html-webpack-plugin: ^5.5.0 => 5.5.0
postcss-loader: ^6.2.1 => 6.2.1
style-loader: ^3.3.1 => 3.3.1
ts-loader: ^9.2.8 => 9.2.8
webpack: ^5.70.0 => 5.72.0
webpack-bundle-analyzer: ^4.5.0 => 4.5.0
webpack-cli: ^4.9.2 => 4.9.2
webpack-dev-server: ^4.7.4 => 4.8.1
copy-webpack-plugin: ^10.2.4 => 10.2.4

Hey there, @igor.chodelka :wave:

Thanks for reaching out! Sorry to hear you are encountering difficulties. Can you please share your netlify site name where this is happening?

Hello, yes, site name is: betbot

Seems like you managed to work around this, or anyway, your builds have succeeded since approximately when you opened this case.

I considered filing a bug on this, but I didn’t think I could speak well to your use case since I don’t understand much about the different ways of loading modules - would you mind opening one for our team at the URL below?

If you do mind, I can take a shot at it for you, but I might misspeak.

I did not manage to fix this bug. I just removed plugin so my site can build. But this is not what I wanted.
I already reported this bug here. copy-webpack-plugin causes build failure · Issue #4260 · netlify/build · GitHub
Feel free to copy paste.

Thanks

thank you igor, that will do just fine! appreciate it. Please keep an eye on that GH issue as we’ll update that as we work on this.