Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Compatibility with Windows Subsystem for Linux #187

Closed
DamianRivas opened this issue Apr 24, 2018 · 25 comments
Closed

Add Compatibility with Windows Subsystem for Linux #187

DamianRivas opened this issue Apr 24, 2018 · 25 comments

Comments

@DamianRivas
Copy link

Feature Request

This is basically a feature request.

I know from the Quokka docs that we can point Quokka to a node executable for it to use. It also says it runs the node command to run our code.

With the way things are right now, I simply can't use Quokka anymore. Since I transitioned to Windows Subsystem for Linux (WSL) to develop node applications, I can't point Quokka directly to node because it's unsafe to directly access the Linux file system from Windows.

But you can safely access the file system from bash. It would be great if Quokka gave us the option to "toggle" WSL.

For example, if you installed node normally in Windows, you would simply run node -v in cmd to get the current version of node.

cmd

node -v

If you installed node in say Ubuntu through WSL, you can still run node commands in cmd if you know the path where the node binary is.

cmd

bash -c "export PATH='/home/<username>/.nvm/versions/node/<node_version>/bin:$PATH' && node -v"

What Would this Look Like?

This is just a suggestion, but maybe we could configure config.json like this:

{
    "useWsl": true,
    "node": "/home/username/.nvm/versions/node/v9.10.0/bin/node"
}

WSL was designed with interoperability with native Windows processes so I think this should be easily feasible. And I like Quokka so I would like to continue using it :)

Code editor version

Visual Studio Code v1.22.2

OS name and version

Windows

@ArtemGovorov
Copy link
Member

Sorry if my question below is obvious, but I have never used WSL.

If you have a local c:\\test.js file and want to run it in node through WSL, how can you do it from cmd? What would the command look like?

@DamianRivas
Copy link
Author

DamianRivas commented Apr 24, 2018

No worries!

Assuming you're not already in the directory, WSL provides the /mnt directory in linux to access the Windows filesystem. So the command would look something like this:

cmd

bash -c "export PATH='/home/username/.nvm/versions/node/v9.10.0/bin:$PATH' && node /mnt/c/test.js"

@DamianRivas
Copy link
Author

Keep in mind that Windows does limit what you can do from within Linux for security reasons. So you wouldn't specifically be able to run JavaScript files sitting in your C: drive's root unless you ran cmd as administrator.

But typically anything goes for any other directory. So if you were to nest the file just once, C:\code\test.js, it wouldn't have any problems.

@rfgamaral
Copy link

rfgamaral commented May 7, 2018

I have the same issue and I tried to configure Quokka without success...

@ArtemGovorov Here's a full example of how one could launch a node process inside WSL to run a specific file based on a Windows path:

wsl.exe /home/Ricardo/.node/bin/node $(wslpath 'C:\Users\Ricardo\Workspace\hello.js')

Explanation:

  • wsl.exe: Recommended method to invoke WSL (https://blogs.msdn.microsoft.com/commandline/2017/11/28/a-guide-to-invoking-wsl/).
  • /home/Ricardo/.node/bin/node: I use n inside WSL to manage my Node versions and this is where it's installed on my machine. It will be different for everyone else.
  • wlspath: Is an built-in interoperability WSL tool to convert between Unix and Windows paths.
  • C:\Users\Ricardo\Workspace\hello.js: the Windows path here the file we want to run is located.

I approve @DamianRivas suggestion to configure Quokka's to something like this (based on my example above):

{
    "useWsl": true,
    "node": "/home/Ricardo/.node/bin/node"
}

Then just use that information to properly launch the node process inside WSL.

I hope this information is useful :)

@ArtemGovorov
Copy link
Member

Haven't tried it so not sure if it's going to work, but I'm wondering if for now it may be possible to create a command/bat file like runwsl that will include the

wsl.exe /home/Ricardo/.node/bin/node $(wslpath 'C:\Users\Ricardo\Workspace\hello.js')

and configure Quokka as

{
    "node": "runwsl"
}

@rfgamaral
Copy link

@ArtemGovorov I tried that but I'm not sure how to pass the opened file to the command...

@rfgamaral
Copy link

@ArtemGovorov Any progress?

@ArtemGovorov
Copy link
Member

@rfgamaral Not yet, I'll post an update here when there'll be some.

@zenion
Copy link

zenion commented Jun 27, 2018

would love to see this as well... i tend to work exclusively from a WSL environment when im on windows so would be gret if this were a reality

@zenion
Copy link

zenion commented Jun 27, 2018

may want to look at how vscode themselves implemented this for their launch.json useWsl: true implementation... may help perhaps

@samplefrequency
Copy link

The next release of Webstorm (2018.2) will have better support to invoke the Node interpreter in WSL. I too, would like to see Quokka support this. Like others here, I work projects running in WSL but use Windows applications (like Webstorm) for editing and such.

@smcenlly
Copy link
Member

smcenlly commented Sep 4, 2018

We've now added support for WSL in Quokka. It was possible to achieve this by overriding your node path, but we've added as a first class feature to make it easier to enable.

For Microsoft Windows environments, Quokka can be configured by editing your global quokka config.json file, located in your %USERPROFILE%\.quokka folder. To use WSL, you must set useWsl to true, for example:

{
    "useWsl": true
}

If configuring a custom version of node, the path must refer to a version of node on your Linux installation. To use this feature, you must enable the Windows Subsystem for Linux and have installed a version of Linux from the Windows Store.

This is available in IntelliJ v1.0.109+, VS Code v1.0.144+, and Atom v1.0.88+.

You can refer to our docs on our website for more information.

@smcenlly smcenlly closed this as completed Sep 4, 2018
@rfgamaral
Copy link

Awesome, thanks guys :)

I just wanted add that I had to configure it like this to get it working (I use n node manager):

{
    "node": "/home/Ricardo/.node/bin/node",
    "useWsl": true
}

If I used ~/.node/bin/node instead, it didn't work. Although it should?

@smcenlly
Copy link
Member

smcenlly commented Sep 5, 2018

Thanks for the feedback. By default, we launch using 'node', which will use whatever version is detected by your operating system.

What version is reported if you run the command below using Windows command-line or Powershell?

wsl node -v

@rfgamaral
Copy link

/bin/bash: node: command not found

@DamianRivas
Copy link
Author

I actually get the same output with powershell. I use nvm in WSL.

λ  wsl node -v
/bin/bash: node: command not found

@smcenlly
Copy link
Member

smcenlly commented Sep 7, 2018

The command not found when running wsl node indicates that node is not referenced in your system path. You can either update your Linux ~/.profile file to add node to your path, or you can reference the node version explicitly in your Quokka configuration.

@rfgamaral
Copy link

rfgamaral commented Sep 7, 2018

@smcenlly I think you might be misunderstanding my problem.

I have referenced the node version explicitly in my Quokka configuration. But the problem is that a relative path based on my home does not work, while an absolute one does:

  • "node": "/home/Ricardo/.node/bin/node" ✔️
  • "node": "~/.node/bin/node"

Shouldn't both work?

@smcenlly
Copy link
Member

smcenlly commented Sep 7, 2018

Thanks for the clarification. Will take a look at this next week and get back to you.

@smcenlly
Copy link
Member

This was an issue in Quokka for VSCode and Atom and has now been fixed. This is available in the latest version of these plugins, Quokka for VSCode v1.0.147 and Quokka for Atom v1.0.90.

@rfgamaral
Copy link

Working now, awesome. Thanks @smcenlly, good job :)

@samplefrequency
Copy link

I'm also using n for my node manager and on the latest version of WSL, I can no longer reference my node installation in WSL. I get the error "runnerw.exe: CreateProcess failed with error 2: The system cannot find the file specified."

Here is my config.json in windows:

{"pro":true, "useWsl":true, "node": "/home/eric/n/bin/node"}

Windows build 1903
Webstorm 2019.1

@smcenlly
Copy link
Member

Thanks for reporting the problem. We've fixed this in the latest version of Quokka for IntelliJ, v1.0.150.

@christianboyle
Copy link

When Node is installed using apt in WSL (Ubuntu 18.04) and without a Node version manager, setting the node option in config.json to be /usr/bin/node (which is what's returned when running which node in WSL Terminal tab) does not work and results in an error:

Error: Can not start node.js process (node), make sure your system has node.js installed.

What ended up working is to have config.json like so:

{
"useWsl": true
}

And then in Windows User Environment Variables add the following to Path:

C:\Users\[username]\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\bin\

  1. Restart VSCode
  2. ctrl+shift+p
  3. Quokka.js: New Javascript File with the following:

var abc = 123;
abc

Should return (with no errors in Output tab):

var abc = 123;
abc 123

@smcenlly
Copy link
Member

@christianboyle - thanks for sharing your solution. In the past we've seen problems with wsl not correctly resolving paths that are set by your wsl terminal's user startup scripts (e.g. .bashrc). You node path should be the fully qualified path to your node executable. We're using nvm so ours looks like this:

{
  "pro":true,
  "useWsl": true,
  "node": "/home/myusername/.nvm/versions/node/v12.13.1/bin/node"
}

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

No branches or pull requests

7 participants