Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

WebPack SPA Services: "cannot find module" when ProjectPath is a different directory #573

Closed

Description

@harsimranb

My react code is stored in the "Web.Platform/Web.Client" directory and my Asp.Net Core application code is stored in "Web.Platform/Web".

app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
 {
     HotModuleReplacement = true,
     ReactHotModuleReplacement = true,
     ConfigFile = @"webpack.config.js",
     ProjectPath = @"..\Web.Client\"
});

When I run my project, I get the following error:

System.AggregateException was unhandled by user code
  HResult=-2146233088
  Message=One or more errors occurred. (Call to Node module failed with error: Error: Cannot find module '..\Web.Client\webpack.config.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.resolve (internal/module.js:27:19)
    at Object.requireNewCopy (C:\Web.Platform\Web.Client\node_modules\aspnet-webpack\RequireNewCopy.js:6:34)
    at createWebpackDevServer (C:\Web.Platform\Web.Client\node_modules\aspnet-webpack\WebpackDevMiddleware.js:133:47)
    at createWebpackDevServer (C:\Users\harsimranb\AppData\Local\Temp\tmp5544.tmp:74:50)
    at C:\Users\harsimranb\AppData\Local\Temp\tmp5601.tmp:113:19
    at IncomingMessage.<anonymous> (C:\Users\harsimranb\AppData\Local\Temp\tmp5601.tmp:132:38)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12))
  Source=System.Private.CoreLib
  StackTrace:
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options)
       at Web.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) in C:\Web.Platform\Web\Startup.cs:line 115

Activity

  1. harsimranb commented on Jan 10, 2017

    @harsimranb
    Author

    I just realized that the ProjectPath is an absolute path, not a relative path. It's obvious because of the temp files, totally missed it. =/ I updated my code to:

    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
     {
         HotModuleReplacement = true,
         ReactHotModuleReplacement = true,
         ConfigFile = @"webpack.config.js",
         ProjectPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "Web.Client")
    });
    

    I am no longer getting that error. Can someone confirm that I have this correct now? Also, would be nice to rename ProjectPath to AbsoluteProjectPath, or perhaps update the summary to acknowledge that.

  2. liddellj commented on Apr 11, 2017

    @liddellj

    @harsimranb I did not realise that ProjectPath was absolute until I read this issue. This allowed me to keep the client app in a separate location from the hosting AspNet application. Thank you.

  3. jonathantorley commented on Sep 7, 2018

    @jonathantorley

    I know this is old, but I think there's a bug there. Specifying a folder (e.g. "ClientApp") results in node looking for the folder incorrectly, but still relative to the project folder (from ProcMon):
    image
    Note the reference to node_modules.

    Can we please get this reopened, or at least get some documentation about it not being relative?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions