Sunday 18 October 2020

ASP.NET Core 2.2 app with Node.js broke after VS update

I think it was the VS update to 16.8.0 Preview 4.0. I am well aware .NET Core 2.2 was deprecated and is no longer supported. I want to understand what is going on.

We inherited a web application that was supposed to be ASP.NET Core with MVC but as it appears it doesn't do much with that infrastructure and instead leans heavily on Node.js. Here's webpack.config.js:

const path = require('path');

module.exports = {
    entry: {
        main: './ClientApp/index.js'
    },
    devtool: 'inline-source-map',
    stats: { modules: false },
    devServer: {
        hot: false
    },
    watchOptions: {
        ignored: /node_modules/
    },
    output: {
        path: path.join(__dirname, '/wwwroot/js/'),
        filename: 'site.js',
        publicPath: '/'
    }
};

An entry point ./ClientApp/index.js is declared and until recently this seemed indeed what was executed when one started the application in Visual Studio with IIS Express and Chrome.

However, since my update I get Index.cshtml instead. Which is exactly what I would expect from an ASP.NET application with MVC.

One remarkable thing I noticed is that under dependencies I no longer see the any/npm branch that used to be there.

My co-workers who are still on Visual Studio 2019 stable still get the old behavior, with index.js kicking in. It looks like request routing behavior has changed.

Re-installing dotnet SDK 2.2 and Node.js with subsequent "npm install" does not fix it, I still get the default page Index.cshtml.

Question: What exactly made the application execute index.js rather than Index.cshtml? I do not find any references in the code to index.js apart from the declaration in webpack.config.js. I would expect to find something that starts node.exe with index.js as an argument, or some statement that wraps that.

I tried to get it working by installing NuGet packages Node.js and Microsoft.AspNetCore.NodeServices, which were never there before. But it does not restore the desired behavior.

[Edit]

It appears it does not matter what I enter for the main entry point in webpack.config.js, it only needs to comply with the schema but it is never even looked for at runtime. I found a way to display the console to see some output. I got rid of some warnings and errors but the result is still the same. It may not be routing after all, it may have been the same page all the time, just now dysfunctional and looking very different as a result. I do not know. Here's the console output, I hope it will provide some alert to more knowledgeable folks:

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\MaatM\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Hosting environment: Development
Content root path: D:\Projects\ProjectName
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.NodeServices[0]
      webpack built 33af367a37b276ede2b3 in 2029ms
info: Microsoft.AspNetCore.NodeServices[0]
      i ´¢ówdm´¢ú: Hash: 33af367a37b276ede2b3
      Version: webpack 4.29.5
      Time: 2029ms
      Built at: 2020-10-16 14:22:53
        Asset      Size  Chunks             Chunk Names
      site.js  6.71 MiB    main  [emitted]  main
      Entrypoint main = site.js
info: Microsoft.AspNetCore.NodeServices[0]
      i ´¢ówdm´¢ú: Compiled successfully.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'Page: /Index'
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
      Route matched with {page = "/Index"}. Executing page /Index
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[101]
      Executing handler method ProjectName.Pages.IndexModel.OnGet with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[102]
      Executed handler method OnGet, returned result .
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[103]
      Executing an implicit handler method - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[104]
      Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[4]
      Executed page /Index in 63.434ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'Page: /Index'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 217.9321ms 200 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/css/site.css?123
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/lib/bootstrap/dist/css/bootstrap.css
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/lib/jquery/dist/jquery.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/js/site.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/lib/bootstrap/dist/js/bootstrap.bundle.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 31.0267ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 31.0331ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 19.6686ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 52.5483ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 52.5487ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/css/site.css?123
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 5.9602ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/lib/jquery/dist/jquery.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 4.1753ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/lib/bootstrap/dist/js/bootstrap.bundle.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 3.914ms 404
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET https://localhost:5001/~/js/site.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 4.3371ms 404

Some puzzling things: I see some garbled characters under the second Microsoft.AspNetCore.NodeServices[0], then the same thing a bit further down. In between it says Entrypoint main = site.js which I did not declare.



from ASP.NET Core 2.2 app with Node.js broke after VS update

No comments:

Post a Comment