我使用VisualStudio2019创建了一个带有ASP.NET模板的React.js Core3.1项目
当我作为React.js应用程序运行该项目时,一切都很好。但是,当我将应用程序更改为NextJS应用程序时,当我运行它时,会给出错误:
AggregateException: One or more errors occurred.
(One or more errors occurred. (The NPM script 'start' exited without indicating that the create-react-app server was listening for requests.
The error output was: Error: Could not find a valid build in the 'C:\Users\myname\source\repos\Panel\Panel\ClientApp\.next' directory! Try building your app with 'next build' before starting the server.
我可以使用npm 运行应用程序,但我想使用visual运行ASP.NET核心应用程序,就像运行React.js应用程序一样。
我如何添加命令,如、npm、运行dev、,并执行它们以在同一个端口上运行应用程序?
发布于 2021-01-30 23:05:36
您需要在Startup.cs中使用反向代理来指向用于启动next.js应用程序的脚本。例如:
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp/nextjs-client";
if (env.IsDevelopment())
{
spa.Options.StartupTimeout = TimeSpan.FromSeconds(120);
spa.UseProxyToSpaDevelopmentServer("http://localhost:3000");
spa.UseReactDevelopmentServer(npmScript: "dev");
}
});
https://stackoverflow.com/questions/64430422
复制相似问题