I'm doing web development on Windows 10 using Windows Subsystem for Linux with Ubuntu 18.04. Using Node.js and NPM inside Ubuntu and running dev servers and API servers works.
When I am inside WSL I can run commands:
npm i
node app
npm run serve
# etc...
And now there is a new situation. I have a project using Nightmare.js (improved but similar to Phantom.js) which will install Electron headless browser when running npm i. Running npm i inside WSL will install Ubuntu version of Electron and when trying to run nothing will happen, browser will not be open. Which is logical because WSL Ubuntu has no visual environment thus can't open a browser in it.
If I run npm i with PowerShell or CMD (npm that is installed on Windows instead WSL will be used), Windows version of Electron will be installed and I can run it with node app inside PowerShell and it will work as expected, browser opens etc...
This creates and interesting precedent. It looks like I will need to sometimes run my applications with Windows commands. Instead of doing npm i or node app directly in WSL I have to switch to CMD or PowerShell and execute them there, so that windows versions of npm and node are used instead of WSL Ubuntu's. This is not very convenient and I would like to do it all from WSL. For an example of this behavior there is Visual Studio Code from Microsoft. With Remote-WSL add-on installed I can run code command inside WSL Ubuntu and VSCode will open in Windows.
Here is my question: Is there a way to link commands in WSL Ubuntu to Host Windows system just like it is done with VSCode? Ideally I would like to have something like this in my WSL Ubuntu: windows-npm i, windows-node app that will run npm and node on the Host Windows System instead of the same commands on WSL Ubuntu.
There is little to no attention to the issue, so I decided to fix my self. I'm still looking for better/native solution but here is a workaround I came up with.
WSL-Link
Allows WSL users to run any CMD commands on host Windows system from within linux subsystem.
Requirements
Windows 10
WSL
Node.js
NPM
Node and NPM have to be installed both in linux subsystem and on Windows host system.
Install
wsl-link has to be installed separately in subsystem and on Windows host
On subsystem linux:
npm i wsl-link -g
On Windows host:
npm i wsl-link -g
Windows Startup
To run script at startup on windows I use PM2 with supplied daemon script.
Install pm2 and pm2-windows-startup on Windows host:
npm i pm2 pm2-windows-startup -g
Install pm2-startup:
pm2-startup install
Run wsl-link pm2 daemon:
wsl-link-pm2
Save pm2 list of processes
pm2 save
You can now confirm that the wsl-link app is running, with:
pm2 status
Usage
On Windows start server (if not using startup setup with pm2):
wsl-link
Use on subsystem linux (npm -v will be run on host Windows):
wsl-link npm -v
Case
On subsystem linux setup a project (or use existing):
mkdir wsl-link-test
cd wsl-link-test
touch app.js
npm init
app.js:
const Nightmare = require('nightmare');
(async () => {
await Nightmare({
show: true
})
.goto('https://google.com');
})();
Install Windows version of Nightmare.js and run it on Windows.
wsl-link npm i nightmare --save
wsl-link node app
You should see Electron browser open on your Windows host.
Related
Whenever running an Appium test while starting appium server am facing an error saying nodejs is either not installed or its executable not present in path
I have installed node-js in my machine also installed appium through the command npm install -g appium
You need to pass two arguments under appiumdriver like in this way AppiumDriver(url,cap);
URL:- appium point url.
Cap:- desiredCapability instance.
I have developed my application on a windows machine and have to deploy this on a standalone UNIX server and while running commands like: npm start, it says that package is not available but I checked and everything is available in the project's npm modules.
Do I need to use docker or how can I achieve that without any container such as docker or kubernete.
Can I try cloning my repo in some other Linux machine and npm install and then use the same folder to deploy on UNIX CentOS running on the server?
I'm a new React Developer, and I'm having a problem in running it to my chrome. I already did the npm install in cmd, and then I npm start by its not starting because of error in cmd. And my OS is Windows 10.
What should I do?
in your package.json file the script define rm command witch is not available in windows that's why you are getting error
insted of rm change it to del
and if there is any UNIX specific command then change it to windows equivalent
I am new to Windows 10. I am building Screencat app for Windows. But when I run the "npm start" in console, I get the below popup asking for how I want to open the js file.
Is it possible to run electron apps in Windows 10?
For Screencat npm start runs the command electron electron.js. It seems that your OS is not recognising electron as a valid command.
Did you follow the instructions (https://github.com/maxogden/screencat#building-the-app) for Windows completely? In particular, installing C++ and installing and running electron-rebuild.
You will need Visual studio C++ installed so you can build the native modules. Here are instructions for cmd.exe
git clone https://github.com/maxogden/screencat.git
cd screencat
npm install
npm install electron-rebuild
.\node_modules\.bin\electron-rebuild.cmd
npm start
I recently decided to pick up Node on my personal laptop, which I upgraded to Windows 10, and the Node cli seems to hang when I try to run it.
Simply typing node on the console will not initiate the interface, and to do anything else I need to Ctrl+C out of it.
Additionally, running some npm commands take longer than they used to on my laptop. More noticeably, npm init seems to hang after confirming the information to be written to package.json.
Node version is 4.0.0
npm version is 2.14.2
Are there any known issues with Node and npm on Windows 10?
Edit:
After some troubleshooting, I've figured out the error only happens on Msysgit. Neither of the issues happen on the standard command prompt of Windows.
I had the same issue on Windows 7 with Node version 6.11.0 and Msysgit's MINGW64 terminal window.
The problem was caused by the an alias provided by Msysgit as demonstrated below:
$ alias node
alias node='winpty node.exe'
The solution is to run the command:
$ unalias node
Then node will run correctly.
You can add the unalias node command into your .bashrc file in your HOME directory to make this permanent.
Good luck!
Jeff