我使用的是角6MVC应用程序与webpack构建。它在页面加载或重定向时随机抛出一个"loadChunkError":true",发生错误后,角路由无法工作,并不断抛出控制台错误。
注意:一旦我清除了浏览器缓存,然后路由就可以正常工作了。
Webpack文件
const webpack = require("webpack");const path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
var SourceMapDevToolPlugin = require('webpack/lib/SourceMapDevToolPlugin');
let SharedCache = {};
const entryPath = path.resolve(__dirname, "src");
const viewPath = path.resolve(
__dirname,
"../Views/Home"
);
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
const ROOT = path.resolve(__dirname, '');const = ${entryPath};module.exports = envOptions => { envOptions = envOptions连体{};
const config = {
entry: {
polyfills: `${entryPath}\\polyfills.ts`,
vendors: `${entryPath}\\vendor.ts`,
app: `${entryPath}\\main.ts`
},
output: {
path: viewPath,
publicPath: '/',
filename: "../../angularBundle/[name].js",
chunkFilename: '../../angularBundle/[name].js',
sourceMapFilename: "../../angularBundle/[name].js.map",
},
resolve: {
extensions: [".ts", ".js", ".html"],
alias: {
jquery: "jquery/src/jquery"
}
},
module: {
rules: [
{
test: /\.ts$/,
loaders: ["awesome-typescript-loader?configFileName=./src/tsconfig.json", "angular2-template-loader"]
},
{
test: /\.(ts|js)$/,
loaders: [
'angular-router-loader'
]
},
{
test: /\.html$/,
loader: "raw-loader"
},
{
test: /\.css$/,
loader: "raw-loader"
}
,
{
test: /\.(png|jpg|eot|cur|svg|gif|ttf|woff|otf)$/,
loader: "file-loader",
options: {
outputPath: 'fonts/'
}
}
]
},
devtool: 'eval',
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: viewPath + "/loader.cshtml",
filename: viewPath + "/Index.cshtml",
inject: false
})
],
optimization: {
splitChunks: { chunks: 'all' },
},
};
if (envOptions.MODE === "prod") {
config.plugins.push(
new UglifyJsPlugin()
);
}
return config;
}; 误差
错误: Uncaught (承诺):Object:{"loadChunkError":true,“details”:{“type”:“缺失”,"request"}
请提出一个或多个解决方案来解决这个问题。
谢谢你,维维克
发布于 2019-03-25 11:22:43
的根本原因:在我的例子中,由于旧的缓存js块,存在加载块错误。
修复:通过在散列的帮助下生成唯一的js来解决这个问题。
散列是“为每个构建生成的唯一散列”。
现有
output: { path: viewPath, publicPath: '/', filename: "../../angularBundle/[name].js", chunkFilename: '../../angularBundle/[name].js', sourceMapFilename: "../../angularBundle/[name].js.map", }
更新[发行固定]
output: { path: viewPath, publicPath: '/', filename: "../../angularBundle/[name].[hash].js", chunkFilename: '../../angularBundle/[name].[hash].js', sourceMapFilename: "../../angularBundle/[name].[hash].js.map", }
发布于 2019-03-24 09:50:52
component而不是loadChildren直接加载组件,然后可以看到实际的错误https://stackoverflow.com/questions/52218987
复制相似问题