ASP.Net Mac 上的核心 Yeoman 模板问题

ASP.Net Core Yeoman Template issue on Mac

我正在尝试 运行 我的 asp.net 由 aspnetcore-spa Yeoman 模板创建的核心应用程序。该项目适用于 windows 但适用于 Mac 我有相同的代码并且 dotnet build dotnet run 已成功完成。但是一旦我向 http://localhost:5000 发送请求,它就会 returns 错误并在服务器端记录这些详细信息: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]

An unhandled exception has occurred: Call to Node module failed with error: Error: Cannot find module '/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/ClientApp/dist/main-server'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at findBootModule (/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/node_modules/aspnet-prerendering/Prerendering.js:98:24)
    at findBootFunc (/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/node_modules/aspnet-prerendering/Prerendering.js:103:5)
    at renderToString (/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/node_modules/aspnet-prerendering/Prerendering.js:10:5)
    at module.exports.renderToString (/private/var/folders/tc/yprt56j93930n80b9g_c6_nc0000gp/T/tmpiaBWzk.tmp:19:46)
    at /private/var/folders/tc/yprt56j93930n80b9g_c6_nc0000gp/T/tmp8l8hSj.tmp:113:19
    at IncomingMessage.<anonymous> (/private/var/folders/tc/yprt56j93930n80b9g_c6_nc0000gp/T/tmp8l8hSj.tmp:132:38)

System.Exception: Call to Node module failed with error: Error: Cannot find module /Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/ClientApp/dist/main-server'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at findBootModule (/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/node_modules/aspnet-prerendering/Prerendering.js:98:24)
    at findBootFunc (/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/node_modules/aspnet-prerendering/Prerendering.js:103:5)
    at renderToString (/Users/FrontEnd/MyCompany_App/MyCompany_App/MyCompanyCore/src/MyCompany.Web/node_modules/aspnet-prerendering/Prerendering.js:10:5)
    at module.exports.renderToString (/private/var/folders/tc/yprt56j93930n80b9g_c6_nc0000gp/T/tmpiaBWzk.tmp:19:46)

我遇到了同样的问题,花了一些时间才意识到我没有 运行 webpack,所以试一试。在项目文件夹中 运行 :

webpack

然后 运行 您的应用:

dotnet run

顺便说一句,默认托管环境是生产环境,只需 运行 此命令将其设置为 develpment,这样您就可以使用 webpack 的热模块替换功能。

export ASPNETCORE_ENVIRONMENT=Development dotnet run