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

Exception: Call to Node module failed with error: To use prerendering, you must install the 'aspnet-prerendering' NPM package. #144

Closed
MarkPieszak opened this issue Jun 21, 2016 · 29 comments

Comments

@MarkPieszak
Copy link
Contributor

MarkPieszak commented Jun 21, 2016

Tried a fresh install from the yeoman generator today, and even after running npm i (the node_modules folder isn't empty, everything is definitely installed) and dotnet restore, when loading up localhost:5000 it shows an internal server error right away. Windows 7 PC. (I have no issues on a separate MAC)

Also, strangely Visual Studio thinks that the dependencies weren't installed:
image

image


When running with F5 through Visual Studio it breaks here, and throws a similar error: Call to Node module failed with error: To use webpack dev middleware, you must install the 'aspnet-webpack' NPM package

image

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Jun 22, 2016

A known issue in VS 2015 Update 2 (and all prior versions) is that it can't correctly restore NPM packages such as the Angular 2 ones due to path length limitations on Windows, and the fact that it uses NPM 2.x instead of NPM 3.x which solves the problem. If VS has been involved in trying to restore your NPM packages, then it's likely that your node_modules is in a bad state, and that will probably explain why aspnet-prerendering was not installed. BTW you can check whether it was installed by looking in the node_modules\aspnet-prerendering folder, which I'm guessing won't existing in your project, or if it does, may contain an incomplete set of files.

If you're using Angular 2 and VS, your options are:

  • Make sure you have NPM 3.x on your machine (run npm -v to check). Then, don't use VS to restore NPM packages. Always do it exclusively from the command line, and if VS has interfered, be sure to delete node_modules completely before running npm install on the command line again.
  • Or, reconfigure your copy of VS to use NPM 3.x (see the earlier discussion at npm Dependencies #119)

The VS team is aware of the need to upgrade to NPM 3.x by default, and I believe has a fix coming not too long from now.

Also, I just checked on a Windows machine that the latest generator-aspnetcore-spa templates for Angular 2 does work OK, including when you launch it from VS, assuming the NPM modules were restored correctly. So I'll close this, but please reopen if you still think there's a bug (beside the VS limitation).

@MarkPieszak
Copy link
Contributor Author

Thanks for your response Steve! So I'm running the latest Node 6x NPM 3x, and the issue still happens even when I closed down Visual Studio, rimraf node_modules then npm i then dotnet run.

The module is definitely there as well, very bizarre.

image

@SteveSandersonMS
Copy link
Member

If there files are definitely in the right place on disk, I'd have to guess that Node is looking for them in the wrong place. There are various ways of configuring where Node finds modules. Or, it might even be possible to launch your app in such a way that the current working directory is something other than the project root, and then the Node instance would look for node_modules relative to the wrong dir.

I'd need to be able to repro this to investigate. So if you have a minimal project that causes the issue, and can post it online somewhere, please let me know. Or if you're able to debug and track down the fault, also please reopen the issue and post details so we can try to be more resilient against whatever condition your app is in.

@joff1979
Copy link

I am having this exact same issue. I am using the Angular Yeoman Template. All NPM Packages have installed correctly and when I use dot net run I get -

Call to Node module failed with error: To use prerendering, you must install the 'aspnet-prerendering' NPM package.

When I open up in VS2015 and run from there I get

Call to Node module failed with error: To use webpack dev middleware, you must install the 'aspnet-webpack' NPM package

Unfortunately I cannot load this to Github for you to view from work but I will try it out at home to see if it is an environmental issue tonight. If I get the same problem I will save the repro.

@joff1979
Copy link

OK so have tested this on my home PC and everything works as expected. (Win 10, Latest Node and NPM)

So this issue is specific to my enviroment at work (Win 7 behind corporate firewall). Not sure where to start in resolving this. Any tips ?

I have tried uninstalling/reinstalling Node, setting the node enviroment path and reinstalling all the various components without any luck.

@justin-echternach
Copy link

I had the same issue, but on windows 10. I was also using Nodist (Node version manager). I uninstalled Nodist. Deleted any Nodist and nodejs dirs under Program Files and Program Files (x86). I also deleted the npm-cache from AppData Roaming and made sure the NODE_PATH env var was deleted. Then I installed the latest version of node.js (node-v6.3.0-x64.msi). Installed global packages ... bower, yo, grunt-cli, gulp, webpack, etc... I then deleted the node_modules dir under my generated aspnet spa app and ran npm install. After all that it is working in prod and dev modes. Hope this info helps.

@joff1979
Copy link

I think I am edging towards a resolution. By editing the source code for SPAServices and adding __dirName to the prerendering error message I was able to establish that Node is running in the User\AppData\Local\Temp Directory when running this app.

So I figured this was why node could not require the npm package. If I copy my Node Modules to that folder I get further, the prerender is found and instead get some errors with vendor.js and main.js. However I suspect that this is more due to my configuration issues than a problem with the code itself. Here is the error detail -

Exception: Call to Node module failed with error: ReferenceError: vendor_99144b2b8400b60c2dc0 is not defined
at Object. (:1:1718)
at webpack_require (:1:339)
at Object.module.exports (:1:1651)
at webpack_require (:1:339)
at Object. (:1:1156)
at webpack_require (:1:339)
at config.directives (:1:559)
at Object. (:1:582)
at Module._compile (module.js:541:32)
at requireFromString (C:\Users\xxx\AppData\Local\Temp\node_modules\require-from-string\index.js:27:4)

I have been looking around for ways to fix my Node configuration but am not having much luck. I have uninstalled and reinstalled several times, removed NODE_PATH etc. without any joy.

I'm guessing there must be a setting somewhere that is causing node to behave strangely. I will keep you posted.

@justin-echternach
Copy link

justin-echternach commented Jul 15, 2016

I got that exact error message when I installed aspnet-prerendering and aspnet-webpack globally ... That was before I did all uninstall. Let me know if you determine the root issue with your environment. My solution didn't explain the root issue for me. BTW I am using the command line and visual studio code not Visual Studio. That is another difference.

@joff1979
Copy link

Ok So it is working now. I had one more stab at reinstalling Node.

This time I -

  • Cleared all npm and node related temp files from User\AppData\Local\Temp,
  • Also removed NPM and NPM Cache from Roaming (Which I had done before)
  • Removed NODE PATH from Environment Variables
  • Uninstalled Node
  • Rebooted
  • Installed node
  • Installed webpack globally - That is it no other pakages
  • Then ran the project (not Expecting it to run) using dotnet run from the command line . And it worked!

Hope this helps someone.

@MarkPieszak
Copy link
Contributor Author

nicely done Joff :)

@yehia2amer
Copy link

yehia2amer commented Jul 20, 2016

i just removed webpack using npm uninstall -g webpack
and used aspnet-webpack insted npm install -g aspnet-webpack

Now everything is working fine !

@MarkPieszak
Copy link
Contributor Author

One of my Win7 (64bit) PCs was also having this issue, but I was using nvm (node version manager for windows), I ended up uninstalling that, uninstalling Node (clearing appdata cache for node/npm etc) Re-installing 6.3 normally, and strangely enough the issue is still there. But the project is able to run on that machine. At this point I have no idea what's causing it :)

image

The project successfully runs so that's good enough!

Just putting this info out there incase anyone else runs into these issues.

@bradyep
Copy link

bradyep commented Jul 24, 2016

I have tried every single suggestion here and no matter what I do or how I try running this app, I get "Exception: Call to Node module failed with error: To use prerendering, you must install the 'aspnet-prerendering' NPM package." every single time.

I have the absolute newest, cleanest install of node and npm. I have never used Visual Studio to run npm install or even run the app. I followed all the directions down to the single letter. aspnet-webpack is clearly installed and has all of its files.

The only way I can get this to run is to kill off all attributes in in index.cshtml, which I'm pretty sure is going to kill off hot loading.

I'm on Windows 10 if that matters.

@MarkPieszak
Copy link
Contributor Author

@SyntonicStudios Are you using node version manager or anything? Suspected that might of been my problem. I removed node completely and deleted all those folders, installed from scratch, semi works on one machine, fine on the other. Strange.

@chris-herring
Copy link

Strange indeed. I'm running win 10 and using nvm and have had no issues with aspnet-prerending.

@SyntonicStudios have you checked that aspnet-prerending exists in the node_modules folder? What project are you running up, one of the templates?

@bradyep
Copy link

bradyep commented Jul 25, 2016

I have never used the node version manager and I did indeed verify that the aspnet-prerendering was populated in the node_modules folder.

I just tried this on my work machine and am getting a completely different error running from VS2015:
System.ComponentModel.Win32Exception
The system cannot find the file specified
at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.LaunchNodeProcess(string entryPointFilename, string projectPath, string commandLineArguments)
at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance..ctor(string entryPointScript, string projectPath, String[] watchFileExtensions, string commandLineArguments)

At work running it from dotnet run seems to work, but the hot reloading doesn't seem to be working properly. It just gives me a flash of the updated content and then quickly reverts to the old stuff. Weird.

I'm afraid this entire setup is just too brittle to be used for me. This is a shame because getting Angular 2 with TypeScript working properly in the same project as ASP.NET Core is bizarrely difficult right now.

@MarkPieszak
Copy link
Contributor Author

Have you tried globally installing webpack and also aspnet-webpack?
What version of Node, Typescript do you have?

Have you done an npm cache clean complete node_modules folder wipe, and reinstall / restore packages? @SyntonicStudios

Brittle indeed, it'll get better soon!

@colltoaction
Copy link

My project was working fine, and now I'm facing this issue. Can't remember any change I made that would've triggered this!

I'm using node v6.3.1.

@MarkPieszak
Copy link
Contributor Author

@tinchou did you install nvm or anything and have multiple nodes running / anything like that?

It is strange it keeps cropping up even after RTM was released. I need to look into what the real issue is that's causing this, but looks like everyone has different reasons.

Try completely deleting node_modules and Restore Packages among other things.
A complete wipe of Node and all related AppData cache node and npm files, and removing Node from path etc, reinstalling worked on 1 PC I had it on.

@SteveSandersonMS What can we log this issue to in terms of aspnet? Seems to be around post rc2 (even with Npm3+)

@colltoaction
Copy link

It's working now.

I had chakracore, node 6 and node 4. I followed all instructions here except for uninstalling the ones I wasn't using (it wasn't on the path, so it shouldn't affect, right?).

That didn't work, so I uninstalled, cleaned again, rebooted, and it worked.

@colltoaction
Copy link

And this just happened again when I switched from Node 5.X to Node 6.5.0 in Azure through the application settings configuration.

I went into Kudu and cleaned the environment with these commands:

cd D:\home\site\repository
git clean -xdf
cd ${env:APPDATA}
rm -r npm-cache
rm -r npm

Then I deployed my app again without success. Any ideas how to better clean my App Service environment?

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Sep 20, 2016

I'm not sure what effect this "cleaning" process would have, but if you have access to a command-line interface on your server, can you check that the webpack and aspnet-prerendering packages are really there?

cd yourapproot
dir node_modules    [see if 'webpack' and 'aspnet-prerendering' are in the output]

... and perhaps more importantly:

node -e "require('aspnet-prerendering')"

This may return useful error information if there's some problem loading the aspnet-prerendering module. Please let us know what you find.

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Sep 20, 2016

And can you just confirm that it's definitely complaining about the absence of aspnet-prerendering, and not about aspnet-webpack? The error messages look similar.

@colltoaction
Copy link

I'm using Azure App Service, and it's a managed service. I get an online console through Kudu at https://{{project}}.scm.azurewebsites.net/DebugConsole/?shell=powershell, but I don't have admin access.

Anyway,

  1. All packages are there
  2. Requiring both aspnet-prerendering and aspnet-webpack from the console as you suggested works fine
  3. The error that I'm getting in my logger (Application Insights) is: Call to Node module failed with error: To use prerendering, you must install the 'aspnet-prerendering' NPM package.
  4. Here is the call stack in case you find it useful: https://gist.github.com/tinchou/48e77c5ab73c2f2e12a3a7a6df3e65ec

Thanks!

@SteveSandersonMS
Copy link
Member

I've published updated versions of Microsoft.AspNetCore.SpaServices, aspnet-webpack, and aspnet-prerendering that return more debugging information in these cases. They will now tell you the underlying error that came back from Node, plus the current directory your app is running in, so you can verify that the packages are in thatdirectory/node_modules.

Can you update to the latest versions of all of these and see if the extra info it gives will help you identify the cause?

@colltoaction
Copy link

colltoaction commented Sep 21, 2016

This is good and sucks at the same time: after upgrading these packages, it's working. So I can't give you debug information, but hopefully the next person will :).

EDIT (I had disabled prerendering...):

This is the exception message now:

Call to Node module failed with error: Prerendering failed because of an error while loading 'aspnet-prerendering'. Error was: Error: Cannot find module 'aspnet-prerendering' at Function.Module._resolveFilename (module.js:455:15) at Function.Module._load (module.js:403:25) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at module.exports.renderToString (D:\local\Temp\tmp4CC7.tmp:5:30) at D:\local\Temp\tmp4CE7.tmp:113:19 at IncomingMessage.<anonymous> (D:\local\Temp\tmp4CE7.tmp:132:38) at emitNone (events.js:86:13) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) Current directory is: D:\home\site\wwwroot

The error is very clear to me now: it's trying to find the prerendering module in the current directory, but I don't deploy the node_modules folder (I removed many of the includes here).

I thought this would be bundled or automatically included, but seems like it's not (could it be?). I'll include node_modules for now, but doesn't seem like a good idea. I had removed it because of the huge time overhead it added to my deployment.

I'll see if I can accomplish anything by bundling aspnet-prerendering.

@sohaibjaved44
Copy link

Hey I'm new to angular2 and facing the same problem, I finally have removed "asp-prerender-module " attribute from my tags to make my 3rd party tool primeNg work.
I could not figure out the reason behind the error "Event not found" same happened with another 3rd party node module too.
Something wrong with pre-rendering module I guess?
has it been fixed ?
and unfortunately it takes 5 minutes to render my UI in development. is it this slow?

@shaban01
Copy link

shaban01 commented Feb 20, 2017

Remove contents of folder "C:\Users<your user>\ node_modules/ "

@derricksimpson
Copy link

@sohaibjaved44 this is primarily related to primeng's use of "Event", which does not exist on the server. I use PrimeNG with this template for an internal tool - without any server-side rendering - and it the application is definitely not slow. The initial view is displayed within a few seconds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests