gajus / write-file-webpack-plugin

Forces webpack-dev-server to write bundle files to the file system.
Other
527 stars 54 forks source link

Support Webpack 4.29.0 breaking change #74

Closed Jack-Works closed 3 years ago

Jack-Works commented 5 years ago

https://github.com/gajus/write-file-webpack-plugin/blob/af0192eaff311a6361264d9f3c538f47849b1dc3/src/WriteFileWebpackPlugin.js#L168

If asset is an instance of SizeOnlySource, it will throw an error on any method except size

Breaking change: https://github.com/webpack/webpack/releases/tag/v4.29.0

Exception stack

Error: Content and Map of this Source is no longer available (only size() is supported)
    at SizeOnlySource._error (node_modules/webpack/lib/Compiler.js:647:10)
    at SizeOnlySource.source (node_modules/webpack/lib/Compiler.js:661:14)
    at getAssetSource (node_modules/write-file-webpack-plugin/dist/WriteFileWebpackPlugin.js:116:24)
    at node_modules/write-file-webpack-plugin/dist/WriteFileWebpackPlugin.js:201:27
    at node_modules/lodash/lodash.js:4911:15
    at baseForOwn (node_modules/lodash/lodash.js:2996:24)
    at node_modules/lodash/lodash.js:4880:18
    at Function.forEach (node_modules/lodash/lodash.js:9344:14)
    at handleAfterEmit (node_modules/write-file-webpack-plugin/dist/WriteFileWebpackPlugin.js:182:24)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:7:1)
    at AsyncSeriesHook.lazyCompileHook (node_modules/tapable/lib/Hook.js:154:20)
    at asyncLib.forEachLimit.err (node_modules/webpack/lib/Compiler.js:432:27)
    at node_modules/neo-async/async.js:2813:7
    at done (node_modules/neo-async/async.js:3521:9)
    at outputFileSystem.writeFile.err (node_modules/webpack/lib/Compiler.js:400:9)
    at MemoryFileSystem.writeFile (node_modules/memory-fs/lib/MemoryFileSystem.js:328:9)
Jack-Works commented 5 years ago

Workaround: Set config.output.futureEmitAssets = false

But this behavior will be default in webpack 5

Jack-Works commented 5 years ago

Hold on! This doesn't get fixed!

Webpack will switch to this new behavior and we don't know if they will give us an option to fall back to the old behavior!!

feorex commented 5 years ago

@Jack-Works Correct path is: config.output.futureEmitAssets=false

septs commented 5 years ago
// TODO webpack 5 remove futureEmitAssets option and make it on by default

https://github.com/webpack/webpack/blob/40755384bfe9725e3105e7b5f9becba2c43f2a5f/lib/Compiler.js#L374

Copy @gajus @feorex @Jack-Works

kievsash commented 5 years ago

In Angular cli 8.3 I got this error for ng build --prod

But ng build --prod --source-map=false worked for me

lukeapage commented 5 years ago

Note - this is removed in webpack 5 beta, so this plugin does not work in webpack 5.

KevinGhadyani-minted commented 4 years ago

I'm on Webpack 5. This plugin is broken for me :/.

idflood commented 4 years ago

It seems that this plugin is not needed anymore with webpack 5 (edit: since webpack-dev-server 3.1.10) 🎉

The webpack-dev-server now has a writeToDisk option and the same is available too with webpack-dev-middleware.

The middleware page even have this description:

If true, the option will instruct the module to write files to the configured location on disk as specified in your webpack config file. Setting writeToDisk: true won't change the behavior of the webpack-dev-middleware, and bundle files accessed through the browser will still be served from memory. This option provides the same capabilities as the WriteFilePlugin.

So thanks a lot @gajus for this excellent plugin, even if it's not needed anymore it will still be used for years to come in already existing projects :)