aspnet / JavaScriptServices

[Archived] This repository has been archived
Apache License 2.0
3.04k stars 519 forks source link

Call to Node module failed - aspnet-webpack #227

Closed navaneethramamoorthy closed 8 years ago

navaneethramamoorthy commented 8 years ago

HI Generator aspnetcore-spa project and tried to run in production mode. but gives below exception. aspnet webpack is installed properly. but still it is not loading the module. there is no change in package.json and project.json

it does not run in both production and development mode as well. is it because am using ASP.NET Core 1.0, instead of ASP.NET CORE RC2.

i want to check Server rendering feature in this project. how to achieve this?

thanks Navaneeth

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. (Call to Node module failed with error: To use webpack dev middleware, you must install the 'aspnet-webpack' NPM package.) ---> System.Exception: Call to Node module failed with error: To use webpack dev middleware, you must install the 'aspnet-webpack' NPM package. at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.d71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.d121.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.d__91.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options) at Ng2ServerRender.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.Internal.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at Ng2ServerRender.Program.Main(String[] args)

aspnet-webpack

SteveSandersonMS commented 8 years ago

is it because am using ASP.NET Core 1.0, instead of ASP.NET CORE RC2.

No, that's not it. Everything here works with the 1.0 RTM. The only thing that even still mentions RC2 is my old blog post that I haven't got round to updating yet :)

aspnet webpack is installed properly

You're probably right, but just to be sure, is there a non-empty directory called aspnet-webpack definitely on disk inside the node_modules directory that is in the root of your project? If on Windows, be sure to check using Windows Explorer, and not just by looking at the list in Visual Studio - I'm not sure you can completely trust what VS shows in that list.

Assuming that directory is there, I wonder if you have a NODE_PATH environment variable set on your machine. Ideally, you wouldn't (though if that does turn out to be the issue, I'd like to know more and find a good solution).

Finally, can you think of anything unusual about your Node installation? Is it perhaps really old, or installed in an unusual location, or you have multiple versions installed, or anything like that? Other people have reported similar issues in the past but I've never had any way of reproing any of them and would love to track down what people have in common when they see this error.

MarkPieszak commented 8 years ago

@navaneethramamoorthy I ran into this on one of my Windows machines. I was using nvm (node version manager) and had multiple versions of Node installed.

What worked for me was:

Then I tried the repo again and everything worked.

nelsonomuto commented 8 years ago

Thanks, I think I will try this suggestion, I am facing the same error. @MarkPieszak

nelsonomuto commented 8 years ago

I tried this but still to no avail @MarkPieszak

nelsonomuto commented 8 years ago

Fortunately after much agony I found a solution. By copy pasting a copy of node.exe to my website virtual directory (global folder) I am able to get it to work. I am not sure why this is the case, I would assume that since node is in my PATH I should not have to do this.

http://stackoverflow.com/questions/38223432/cannot-run-asp-net-core-angular-2-server-side-rendering-project-in-server

SteveSandersonMS commented 8 years ago

Glad you found a workaround.

FYI I think the underlying issue was just fixed in pull request #248, so this should no longer affect anyone (assuming they get NodeServices 1.0.0-beta-000010 or later).

tmc101 commented 7 years ago

In case anyone else sees this, I got the following error trying to run the published project in production mode after hard wiring the environment variable ASPNETCORE_ENVIRONMENT=Development on my dev machine.

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

Without ASPNETCORE_ENVIRONMENT it works fine.

martinfletcher commented 7 years ago

What about running in development on local IIS?

Currently, I have multiple projects that need to be run in development environment but i can not set the ASPNETCORE_ENVIRONMENT to development when publishing to local IIS.....

Is there a work around?

SteveSandersonMS commented 7 years ago

@martinfletcher You can set env variables for IIS processes as described here: https://www.iis.net/configreference/system.applicationhost/applicationpools/add/environmentvariables

martinfletcher commented 7 years ago

@SteveSandersonMS Thanks, I had already done that, but still did not work.

I discovered (from the source code) that http binding is required for aspnet-webpack (hard coded localhost on http).

I take it this will now break if i have require https filters in place? Is there specific urls that i can exclude from this, or ideally a better way of not having to have http binding for my app?

martinfletcher commented 7 years ago

https://github.com/aspnet/JavaScriptServices/issues/883#issuecomment-296186331

isaacrlevin commented 7 years ago

I am getting this error after I upgraded a project to 2.0. Everything works fine except HotModule. Here is the full error

One or more errors occurred. (Call to Node module failed with error: Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: C:\Development\Web\node_modules\webpack\lib\webpack.js:7
const Compiler = require("./Compiler");
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

Here is the code it errors on

  if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
        app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
        {
          HotModuleReplacement = true
        });

npm verison

{ 'web': '1.0.0-rc3',
  npm: '2.7.4',
  http_parser: '2.3',
  modules: '14',
  node: '0.12.2',
  openssl: '1.0.1m',
  uv: '1.4.2-node1',
  v8: '3.28.73',
  zlib: '1.2.8' }
SteveSandersonMS commented 7 years ago

@isaac2004 You're running a very old version of Node. You might need to update that. If that doesn't fix it, could you figure out what are the minimal steps to reproduce the issue based on a new project? Then we can investigate.

isaacrlevin commented 7 years ago

Upgrading Node seemed to fix the issue...

dkent600 commented 7 years ago

Upgrade Node to what? I'm using node v8.1.2 and am experiencing this problem. I have set ASPNETCORE_ENVIRONMENT=Development globally on my Windows 10 machine.

dkent600 commented 7 years ago

When I attempt to use web.config to override the global system environment setting for ASPNETCORE_ENVIRONMENT to force it from "Development" to "Production", it simply doesn't work; the application (ASP.NET Core running in IIS) still thinks the environment is "Development".

The only way I've found alter the environment setting is to alter the actual environment variables.

joepadz commented 7 years ago

Fixed my issue by updating the NodeJS.

ADefWebserver commented 6 years ago

I ran into this problem when publishing on Azure because my app settings file was named: appsettingsDev.json but the ASPNETCORE_ENVIRONMENT variable in Azure (App Services/select the app/Application Settings) was set to "Development" (so it was looking for a file called "appsettingsDevelopment.json" not "appsettingsDev.json").

I changed the ASPNETCORE_ENVIRONMENT value to "Dev" and the problem went away.

jrmcdona commented 6 years ago

Hi All, Is node_modules folder supposed to be on the server? I do not see this folder in my production site which works.

For some reason our latest deployment to test has causes this same issue.