在.Net Core 2.0和更高版本中使用"dotnet发布"时找不到模块"aspnet-webpack"角度的 [英] Cannot find module 'aspnet-webpack' when using 'dotnet publish' in .Net Core 2.0 & Angular

查看:160
本文介绍了在.Net Core 2.0和更高版本中使用"dotnet发布"时找不到模块"aspnet-webpack"角度的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试解决此问题,但无济于事.我正在尝试发布.Net Core 2.0&使用命令行命令"dotnet publish"成功完成了Angular项目,但是当尝试在已发布的文件夹中运行项目的.dll时,在开发环境中运行时,我的项目会吐出此错误:

未处理的异常:System.AggregateException:发生一个或多个错误. (Webpack开发中间件由于加载"aspnet-webpack"时出错而失败.错误为:错误:找不到模块"aspnet-webpack"

在生产环境中运行并允许使用DeveloperExceptionPage(如下面的statup.cs中所示)时,.netcore应用程序运行,但在实际的Web应用程序中崩溃,我认为这是由于较大的错误引起的,aspnet-webpack不是被发现:

NodeInvocationException:未捕获(承诺):错误:找不到HomeComponent的组件工厂.您是否将其添加到@ NgModule.entryComponents中?

Startup.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });
        }
        else
        {
            //app.UseExceptionHandler("/Home/Error");
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new { controller = "Home", action = "Index" });
        });
    }
}

我没有使用@Angular/Cli,但是我使用的是VS2017(我相信是8月更新,)生成的默认Angular Project,它似乎仅使用Webpack.问题似乎是该项目的Production配置需要我没有提供的引用,但我不知道为什么这样做.

到目前为止,这个问题没有其他答案对我有帮助,因此,如果这是重复问题,我深表歉意.

解决方案

我在使用"aspnet-webpack"时遇到了同样的问题,该问题在项目开发的中途才引入,因此看到该解决方案突然失效,我感到很惊讶.几个月在IIS上一切正常,但突然无法启动.

IIS日志文件没有帮助,因此我尝试解决这两种方法,其中一种有效. 快点!

解决方案

我在包管理器"窗口中运行以下命令:

dotnet run --project <Full path of *.csproj> --configuration Debug

它给了我一些指示,我开始搜索"Error: Cannot find module 'aspnet-webpack'"问题.我尝试检查了最后几次签入的所有更改,发现我们将"Microsoft.AspNetCore.All"从2.0.0更新到了2.0.3版本,因此将其降级为原始版本可以解决该问题.

我猜他们都使用不同版本的节点包.因此,除非有充分的理由,否则不要为求更新.仔细阅读这些内容会与特定版本紧密相关,如果发生某些更改,Angular会很容易中断.尽管我已经设法将节点版本升级到最新的5.0.0

喜欢查找更多详细信息,但暂时没有为什么需要特定版本的详细信息.

I have been trying to follow answers to this problem but to no avail.. I am trying to publish my .Net Core 2.0 & Angular project using the command line command 'dotnet publish' I successfully publish, however when trying to run my project's .dll in the published folder, my project spits in out this error when run in a development environment:

Unhandled Exception: System.AggregateException: One or more errors occurred. (Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: Error: Cannot find module 'aspnet-webpack'

When run in Production and allowing for the DeveloperExceptionPage (as shown in my statup.cs below) the .netcore app runs, but crashes within the actual web app, which I assume is due to the larger error, aspnet-webpack not being found:

NodeInvocationException: Uncaught (in promise): Error: No component factory found for HomeComponent. Did you add it to @NgModule.entryComponents?

Startup.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });
        }
        else
        {
            //app.UseExceptionHandler("/Home/Error");
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new { controller = "Home", action = "Index" });
        });
    }
}

I am not using @Angular/Cli, but I am using the default Angular Project that VS2017 (August update, I believe?) generates, which seems to only use Webpack. The problem seems to be that the Production config of the project expects a reference that I am not providing, but I can not figure out why that is.

No other answers to this question have helped me thus far, so I apologize if this is a repeat question.

解决方案

I had same issue with "aspnet-webpack", this was introduced halfway in the project development so I was bit surprised to see sudden death of the solution. It was all working fine couple of months on IIS but suddenly failed to boot.

IIS log files were not helpful, so I tried to resolve this couple of ways, one of them worked. Hurry!

Solution

I ran following on package-manager window :

dotnet run --project <Full path of *.csproj> --configuration Debug

It give me some pointers and I started searching for "Error: Cannot find module 'aspnet-webpack'" issue. I tried to go through all the changes for last couple of check-ins, and found out that we updated the "Microsoft.AspNetCore.All" from 2.0.0 to 2.0.3 version, so downgrading it to original version fixed it.

I guess they both uses different versions of node packages. So don't update for sake unless for a very good reason. Reading around this some bits are very tightly coupled to specific versions and Angular very easily breaks, if something changed. In process though I have managed to upgrade the node version to latest 5.0.0

Love to find more details, but for time being no details on why it needs a specific version.

这篇关于在.Net Core 2.0和更高版本中使用"dotnet发布"时找不到模块"aspnet-webpack"角度的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆