madskristensen / JavaScriptPrettier

A Visual Studio extension
Other
158 stars 30 forks source link

Does not install node module prettier #1

Closed ciwchris closed 7 years ago

ciwchris commented 7 years ago

Installed product versions

Description

Does not install node module prettier

Steps to recreate

  1. Install JavaScript Prettier extension through VS extension manager
  2. Restart VS
  3. Open up a JavaScript file within a solution

Current behavior

Context menu item is grayed out with the text "(installing npm modules...)"

Expected behavior

I checked the location this plugin attempts to install the prettier node module and the module was not installed there. I restarted VS again to see if it would install, it still did not. I did not see any error messages indicating there was a failure. I manually installed prettier at the expected location. Afterwards the menu item was active. Also, a note here just for awareness but will potentially be a new issue, once the menu item was active it didn't seem to perform any formatting.

Also, I think it would be helpful if the README stated it will install prettier itself, at first I thought it was going to try to use the global version installed by yarn.

I do appreciate the creation of this extension, I was pleasantly surprise to see VS listed as a supported editor.

madskristensen commented 7 years ago

It sounds like it can't find node.exe. Do you not have node.exe on you PATH environment variable? If you have the latest ASP.NET Web Development Tools installed you shouldn't need node installed at all, but perhaps my logic for adding VS's node.exe to the PATH is not working properly.

ciwchris commented 7 years ago

Yes, it is on the path.

c:\d>echo %path%
…;C:\Program Files\nodejs\;…

In fact it's there twice.

I opened up C# Interactive in VS and started replicating the steps in NodeProcess.cs.

string _installDir = @"C:\Users\username\AppData\Local\Temp\JavaScript Prettier\296021706";
string Packages = "prettier";
var start = new ProcessStartInfo("cmd", $"/c npm install {Packages}")
{
    WorkingDirectory = _installDir,
    UseShellExecute = false,
    RedirectStandardOutput = true,
    CreateNoWindow = true,
};
string path = start.EnvironmentVariables["PATH"];
var process = Process.GetCurrentProcess();
string ideDir = Path.GetDirectoryName(process.MainModule.FileName);
string parent = Directory.GetParent(ideDir).Parent.FullName;
string rc2Preview1Path = new DirectoryInfo(Path.Combine(parent, @"Web\External")).FullName;
path += ";" + Path.Combine(ideDir, @"Extensions\Microsoft\Web Tools\External");
path += ";" + Path.Combine(ideDir, @"Extensions\Microsoft\Web Tools\External\git");
start.EnvironmentVariables["PATH"] = path;
var proc = Process.Start(start);
proc.WaitForExit();

This installed the node module, but did end with the error:

npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\username\AppData\Local\Temp\JavaScript Prettier\296021706\package.json'

Also, I don't have an Extensions directory, which is created in the Path.Combine statements.

I haven't tried debugging an extension before. If I clone the project is there a way to step through the extension as it runs?

creage commented 7 years ago

Same for Visual Studio 2017 RC (26206)

madskristensen commented 7 years ago

@creage Do you have ASP.NET Web Development workload installed in VS2017?

creage commented 7 years ago

Apparently - yes, it comes preinstalled/activated for the Web development environment, I believe.

madskristensen commented 7 years ago

@ciwchris @creage Can you guys try the CSS Sorter extension to see if you get the same error? It uses the same mechanism for installing node modules, but has more telemetry displayed in the Output Window which might be helpful for diagnostics.

ciwchris commented 7 years ago

Yeah, same results. I didn't see anything in the Output Window. When should I expect to see something? When the extension is installed? After restarting VS? After loading a solution? After opening a CSS file? And in the "Show output from" dropdown should "General" be selected?

madskristensen commented 7 years ago

Weird. Do you have node.exe and npm.cmd at this location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Web\External?

Where Enterprise is the name of the SKU you've got installed

creage commented 7 years ago

I do. But I have different order of folders in the "Location of external tools" under the "Project and Solutions/Web Package Management/External Web Tools". And when I restart my VS2017, I got very short message at the bottom, saying that installing Prettier npm module is failed.

madskristensen commented 7 years ago

I just released version 0.6.16 which writes everything out to the Output Window. Can you try that version and see what the error you get is? And btw, thank you so much for helping troubleshoot this. I'm trying to come up with a generic way to use node modules from VS extensions and need to nail this aspect so it "just works".

ciwchris commented 7 years ago

That fixed it! The module installed and it runs! Thank you :star:

madskristensen commented 7 years ago

awesome. Thanks so much :)

madskristensen commented 7 years ago

@creage if I can get you to try it too just to verify, that would be super helpful.

creage commented 7 years ago

@madskristensen Thanks a lot - it finally works! But, is there any way to configure it? I believe, VS Code plugin has that option.

madskristensen commented 7 years ago

Great. Thanks for all the help!!!