Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 无法将[chunkhash]或[contenthash]用于';[name].[chunkhash].js';(改为使用[hash]_Webpack - Fatal编程技术网

Webpack 无法将[chunkhash]或[contenthash]用于';[name].[chunkhash].js';(改为使用[hash]

Webpack 无法将[chunkhash]或[contenthash]用于';[name].[chunkhash].js';(改为使用[hash],webpack,Webpack,尝试在配置中使用哈希运行webpack build时出现此错误: ERROR in chunk main [entry] [name].[chunkhash].js Cannot use [chunkhash] or [contenthash] for chunk in '[name].[chunkhash].js' (use [hash] instead) 网页包开发服务器运行正常 原因是什么?注释掉了新的网页包。插件中的HotModuleReplacementPlugin()帮助解决了这

尝试在配置中使用哈希运行
webpack build
时出现此错误:

ERROR in chunk main [entry]
[name].[chunkhash].js
Cannot use [chunkhash] or [contenthash] for chunk in '[name].[chunkhash].js' 
(use [hash] instead)
网页包开发服务器运行正常


原因是什么?

注释掉了
新的网页包。插件中的HotModuleReplacementPlugin()
帮助解决了这个问题这对我也很有效……多亏了@pizzaae。有一件事需要注意,那就是你。如果您想同时使用HotModuleReplacementPlugin和chunkash,为Prod和Dev配置不同的网页包会有所帮助

如果在“开发”模式下配置webpack.HotModuleReplacementPlugin()。删除或注释掉 webpack.HotModuleReplacementPlugin()表单插件

module.exports = merge(common, {
  mode: 'development',
  devtool: 'inline-source-map', // source-map
  devServer: {
      contentBase: './dist',
      //hot: true
  },
  plugins: [
      new ManifestPlugin({fileName: '006.manifest.json'}),
      new webpack.NamedModulesPlugin()
      //new webpack.HotModuleReplacementPlugin()
  ]
})

在我的例子中,我想为dev服务器启用热模块替换,因此我将其更改为:

output: {
    filename: '[name].[hash].js',
},

我做了类似的事情,所以你没有注释功能

output: {
    filename: process.env.production ? `bundle-[chunkHash].js` : `bundle-[hash].js`
}

ChunkHash只能在生产中使用。

我的解决方案是根据生产模式还是开发模式更改文件名:

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


修复了我的问题,仍然能够对我的生产文件名以及HotModuleReplacementPlugin使用chunkhash。

奇怪的是,我得到了相反的结果。开发人员服务器错误,构建工作正常。通过删除
--hot
,也为我解决了这个问题,但这不是一个真正的解决方案:)你在哪里更改它?它在我的webpack.config.js文件的输出部分。如果你需要HotModuleReplacementPlugin,这是一个怎样的解决方案?根据环境的不同,你可以有不同的配置。您可能不需要在需要
HotModuleReplacementPlugin
+1的同时在文件名中使用散列。非常有用,因为我在尝试在本地开发服务器上构建生产模式时忘记了删除
--hmr
ng serve--prod--hmr
)。