Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use [chunkhash] or [contenthash] for chunk in '[name].[chunkhash].js' (use [hash] instead)

Tags:

webpack

I'm getting this error when trying to run webpack build with hashing in my config:

ERROR in chunk main [entry]
[name].[chunkhash].js
Cannot use [chunkhash] or [contenthash] for chunk in '[name].[chunkhash].js' 
(use [hash] instead)

Webpack dev server runs fine

What is the reason for this?

like image 694
pizzae Avatar asked May 07 '18 15:05

pizzae


3 Answers

Commented out new webpack.HotModuleReplacementPlugin() in the plugins helped fix this

like image 73
pizzae Avatar answered Nov 15 '22 11:11

pizzae


My solution was to change the filename depending on whether the mode is production or development:

filename: mode === 'production' ? '[name].[chunkhash].js' : '[name].[hash].js',

Fixed my problem and still able to use chunkhash for my production filenames as well as HotModuleReplacementPlugin.

like image 21
Dan Buda Avatar answered Nov 15 '22 10:11

Dan Buda


This worked for me too...thanks to @pizzaae. One thing to note, is that you never want to enable HMR during production. Having different Webpack configs for Prod and Dev can help if you want to use both HotModuleReplacementPlugin and chunkash.

like image 6
Carlos Henriquez Avatar answered Nov 15 '22 12:11

Carlos Henriquez