当我运行基于 .NET Core 3.1 的项目时,我在命令提示符下收到此错误,该项目也在其中使用了 React
fail: Microsoft.AspNetCore.SpaServices[0]
(node:15004) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
fail: Microsoft.AspNetCore.SpaServices[0]
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:15004) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
warn: Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware[4]
Unable to configure browser refresh script injection on the response. This may have been caused by the response's Content-Encoding: 'gzip'. Consider disabling response compression.
这是我认为出现问题的中间件代码
`app.UseSpaStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
if (ctx.Context.Request.Path.StartsWithSegments("/static"))
{
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromDays(365)
};
}
else
{
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromDays(0)
};
}
}
});`
` app.UseSpa(spa =>
{
spa.Options.SourcePath = "./branding-client";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromDays(0)
};
}
};
if (env.IsEnvironment("Development"))
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});`
我已经搜索并找到了几个答案,有些人说要在我的中间件中添加 setUpMiddlewares 一些谎言
spa.UseReactDevelopmentServer(npmScript: "start" , setUpMiddleware => {});
但是这是不可能的,因为这个方法没有这样的重载。
我尝试将 Nuget 包更新到最大兼容版本