Docker support: SPA angular and .NETCore 2.0
I'm trying to add docker to template angular spa with .NET Core 2.0. I added docker support with Visual Studio 2017 and when I launch the application with docker-compose I have an error in
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, });
This is the exception:
One or more errors occurred. (Failed to start Node process. To resolve this:.\n\n[1] Ensure that Node.js is installed and can be found in one of the PATH directories.\n Current PATH environment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\n Make sure the Node executable is in one of those directories, or update your PATH.\n\n[2] See the InnerException for further details of the cause.)
The dockerfile has:
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
I've modified the Dockfile with:
FROM microsoft/aspnetcore:2.0 AS base
RUN curl -sL https://deb.nodesource.com/setup_8.x
RUN bash -
RUN apt-get -y update
RUN apt-get install -y build-essential nodejs
RUN ln -s /usr/bin/nodejs /usr/bin/node
WORKDIR /app
EXPOSE 80
When I launch Dockercompose I have the following error on the same line:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Unexpected token {
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/app/node_modules/@ngtools/webpack/src/index.js:30:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10))
Source=<Cannot evaluate the exception source>
StackTrace:
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options)
at WebApplication12.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in c:\users\usuario\source\repos\WebApplication12\WebApplication12\Startup.cs:line 34
Inner Exception 1:
NodeInvocationException: Unexpected token {
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/app/node_modules/@ngtools/webpack/src/index.js:30:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
Of course i'd like to use HMR with webpack and Docker
Please see this tip from @dapalmi who made it work: https://github.com/aspnet/JavaScriptServices/issues/1534#issuecomment-366605094
My docker file has following test and everything works fine:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base RUN apt-get update -y && apt-get install -y gnupg2 && curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update -y && apt-get install -y nodejs WORKDIR /app .....