Setting up a LESS file watcher in PHPStorm 6 using node.js on Windows? - windows

I'm a recent convert to PHPStorm and absolutely loving it. I'm trying to get the 'File Watcher' to work with my LESS code, and I want it to use the lessc command. I have node.js installed and the command 'lessc' works from the windows command prompt, but it doesn't want to work within PHPStorm.
Here is my configuration for the file watcher:
When the file watcher runs, I get this error appear continuously:
An exception occurred while executing watcher 'LESS'. Watcher is
disabled. Fix it.: Cannot run program
"C:\Users\Jason\AppData\Roaming\npm\lessc" (in directory
"F:\Plan2Share_v1\public\css"): CreateProcess error=193, %1 is not a
valid Win32 application
As soon as I enable the watcher again, it somehow disables and throws me the above error again. I'm very new to node.js and PHPStorm. Any direction on where I might be going wrong would be greatly appreciated.
EDIT: Following #josh3736 's direction. I now get his error in the Run console of PHPStorm.
"C:\Program Files\nodejs\node.exe" C:\Users\Jason\AppData\Roaming\npm\lessc F:\Plan2Share_v1\public\css\style.less
C:\Users\Jason\AppData\Roaming\npm\lessc:2 basedir=`dirname "$0"`
^ SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

That error tells us that PHPStorm is calling CreateProcess, which can only start executables. It cannot run scripts/batch files, which is what lessc is. (PHPStorm would have to use ShellExecute for that.)
To work around this limitation, you'll have to specify the Node installation (C:\Program Files\nodejs\node.exe most likely) as the executable, and the arguments should probably be something like C:\Users\Jason\AppData\Roaming\npm\node_modules\less\bin\lessc $FileName$

Change Program: C:\Users\Jason\AppData\Roaming\npm\lessc.cmd
Change Arguments: --no-color $FileName$
Apply
Image: https://dl.dropboxusercontent.com/u/4287697/2014-09-26_11h25_29.png

Related

Cannot run Visual Studio code script via symlink

So, I built Visual Studio Code from source and intend to keep using it like that. But now everytime I want to open it I have to run a script from its directory. I made a symlink to that script in my /usr/local/bin but unfortunately when I run it it says this:
device:scripts work$ sudo code
Password:
module.js:550
throw err;
^
Error: Cannot find module './product.json'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at [eval]:1:1
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at Object.runInThisContext (vm.js:139:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:653:30)
at evalScript (bootstrap_node.js:479:27)
module.js:550
throw err;
^
Error: Cannot find module '/usr/local/build/lib/electron.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
/usr/local/bin/code: line 29: ./node_modules/.bin/gulp: No such file or directory
module.js:550
throw err;
^
Error: Cannot find module '/usr/local/build/lib/builtInExtensions.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
/usr/local/bin/code: line 41: ./node_modules/.bin/gulp: No such file or directory
/usr/local/bin/code: line 50: /usr/local/.build/electron/.app/Contents/MacOS/Electron: No such file or directory
/usr/local/bin/code: line 50: exec: /usr/local/.build/electron/.app/Contents/MacOS/Electron: cannot execute: No such file or directory
I perfectly understand that it cannot access some files, but I don't understand why. Are there any nuances regarding running electron apps?
Okay, guys. I think I solved this problem. When I ran code.sh via symlink it tried to find necessary files in the directories from my PATH variable. As I intended to run this script from anywhere but original folder they obviously wouldn't be found. So all I had to do was exporting original script directory to PATH.
As I didn't want to bloat my PATH I wrote a little helper script and made a symlink to it from /usr/local/bin/
Here's the code:
#!/bin/sh
export PATH=$PATH:/Users/work/Stuff/vscode/
cd /Users/work/Stuff/vscode/
./scripts/code.sh

Running Processing sketches in the Atom editor

I am trying to use the Atom text editor for Processing development in Windows, and am having some issues. Internet restrictions at work mean I cannot use the built-in package manager within Atom:
Fetching featured packages failed: connect ECONNREFUSED
Therefore, I need to install packages manually. I am trying to use bleikamp's Processing package for atom which allows the running of processing sketches, and have unzipped the package, downloaded from github, in the packages folder - C:\Users\my_username\.atom\packages.
The package is detected within Atom as being installed, but when I try and run a sketch, the below error occurs:
Failed to activate the processing package
Cannot find module 'ps-tree'
Error: Cannot find module 'ps-tree'
at Module._resolveFilename (module.js:455:15)
at Module._resolveFilename (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\electron.asar\common\reset-search-paths.js:35:12)
at Function.Module._resolveFilename (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\module-cache.js:383:52)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\native-compile-cache.js:50:27)
at Object.<anonymous> (file:///C:/Users/chris.hamilton/.atom/packages/processing-master/lib/processing.coffee:4:10)
at Object.<anonymous> (file:///C:/Users/chris.hamilton/.atom/packages/processing-master/lib/processing.coffee:1:1)
at Module._compile (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\native-compile-cache.js:109:30)
at Object.value [as .coffee] (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\compile-cache.js:216:21)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\native-compile-cache.js:50:27)
at Package.module.exports.Package.requireMainModule (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\package.js:796:27)
at Package.module.exports.Package.activateNow (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\package.js:207:16)
at C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\package.js:876:25
at Function.module.exports.Emitter.simpleDispatch (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\event-kit\lib\emitter.js:25:14)
at Emitter.module.exports.Emitter.emit (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\event-kit\lib\emitter.js:129:28)
at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\command-registry.js:240:20)
at C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\command-registry.js:3:59
at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\atom-keymap\lib\keymap-manager.js:599:16)
at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\atom-keymap\lib\keymap-manager.js:390:22)
at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\window-event-handler.js:106:36)
at HTMLDocument.<anonymous> (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\window-event-handler.js:3:59)
I assume this is an issue with dependencies and I am probably missing a step in manually installing the package - can anyone offer any guidance? I have researched fairly extensively into manually installing packages, and there is a lot of information about using commands such as apm link and apm install, but I can't seem to access these commands.
EDIT: I have included processing-java in my PATH variable. Below is the output when path is called from cmd:
PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\ProgramData\Oracle\Java\javapath;C:\WIN
DOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPow
erShell\v1.0\;C:\Program Files (x86)\Microsoft Office\Office14\;C:\Program Files
(x86)\Enterprise Vault\EVClient\;C:\Program Files\Hummingbird\Connectivity\14.0
0\NFS Maestro\;C:\Program Files (x86)\Hummingbird\Connectivity\14.00\NFS Maestro
\;C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v713\runtime\win32;C:\WI
NDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Sh
ared\;C:\Program Files\MATLAB\MATLAB Runtime\v90\runtime\win64;C:\Program Files\
TortoiseSVN\bin;C:\ChrisHamilton\Room_Results_Comparison\processing-3.2.1\;C:\Us
ers\chris.hamilton\AppData\Local\atom\bin
Any help would be much appreciated.
As you have guessed already, missing package dependencies are causing this error. Since you don't seem to have internet connection (or limited connection) at work, I'd recommend installing the Processing package where you are online (e.g. at home), then compress the processing folder and extract it inside the Atom packages folder at work. Make sure the processing folder includes node_modules. Optionally repeat those steps for the script package.
Dependencies are installed running apm install (or npm install) inside the package folder. Whenever an Atom package has dependencies, this step is essential. Atom (or apm) are doing this automatically.
To give you some more insights into the process, here's an alternative way to install a package with dependencies:
cd %USERPROFILE%.atom\packages
git clone https://github.com/bleikamp/processing
cd processing
npm install
It looks like you're running Windows and processing-java hasn't been added to your PATH. Try the following:
Open Advanced System Settings either by running sysdm.cpl or searching in Control Panel.
Click the Environment Variable button on the Advanced tab.
Edit the PATH variable to include the Processing directory (e.g. C:\Program Files\Processing-3.1.1\) in either the User variables (for just your account) or System variables (for all users).
Also note that bleikamp no longer maintains his Processing package and instead recommends using Script.

Cordova 4.3.0 - build command returns error Cannot find module 'Q'

After updating cordova to version 4.3.0 the command:
cordova build
returns the following error:
module.js:340
throw err;
^
Error: Cannot find module 'Q'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Volumes/CaseSensitive/ios_projects/_Tests/testGruntCordova/testGruntCordova/platforms/ios/cordova/lib/check_reqs.js:25:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
ERROR building one of the platforms: Error: /Volumes/CaseSensitive/ios_projects/_Tests/testGruntCordova/testGruntCordova/platforms/ios/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: /Volumes/CaseSensitive/ios_projects/_Tests/testGruntCordova/testGruntCordova/platforms/ios/cordova/build: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)
I have already tried to remove and add the platform ios but nothing changes.
I have tried to run:
sudo npm install -g cordova / sudo npm install cordova
sudo npm install -g Q / sudo npm install Q
but nothing changes.
Any help?
Thank you very much
There was a bug and I have released a patch to it:
Apache Cordova ios - Git Repository
This is a bug shown on case-sensitive systems such as Unix, Linux and some OS X (if set as case-sensitive).
So far, to fix it, you have to locate those files containing a line like this:
Q = require('Q')
You can locate the files while standing on your project directory using grep:
grep -HnrI "require('Q" *;
then, use any text editor to manually change the mentioned line to:
Q = require('q')
Alternatively you can edit the related files on a more straight forward way by running the following command on your project directory:
grep -rl "require('Q" * | xargs sed -i "" "s/'Q'/'q'/g";
The single line above searches and edits the files that need the change.
Removing and then re-adding the platform again also works:
cordova platform remove ios
cordova platform add ios
Now you can cordova build ios :)
As mentioned by MeV this was a bug.

"cannot find module" when installing npm modules on windows

I am new to NodeJS. I am trying to use npm on Windows 8.
I have installed using chocolatey, cinst nodejs.install (version 0.10.17). I installed as administrator (and would prefer to run npm as a normal user).
Node itself seems to be working, I can use the REPL to run simple programs.
If I try to install something using npm, I get cannot find module:
> node npm install express
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\Klas\Documents\My Dropbox\mina egna\tech\node\webserver\npm'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
I have read the answers on Nodejs cannot find installed module on Windows? but unfortunately it is still unclear to me what I have to do.
I have tried setting NODE_PATH:
In trying to follow this answer, I have tried setting it to C:\Users\Klas\AppData\Roaming\npm\node_modules (but I had to create both the npm and the subfolder node_modules myself)
I have tried creating a folder c:\node\node_module (according to this advice, even though the installation did not even create a c:\node folder) and setting it to that.
I have tried setting it to C:\Program Files\nodejs\node_modules\npm\node_modules (which did exist after installation)
I have also tried to create a node_modules folder below the current working directory. As I understand it that is where local npm will be installed?
None of these helped. So it seems to me that setting NODE_PATH is not the solution?
Using the -g flag makes no difference (I would prefer not to use it).
I get the same error both as normal user and as administrator (I would prefer to be a normal user).
I get the same error no matter where I execute the command, except when I do it in C:\Program Files\nodejs, where I get
basedir=`dirname "$0"`
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
Not using windows, but I'm pretty sure it's just npm install express on windows too.

Why am I getting errors running the coffee command in cygwin?

I followed the CoffeeScript installation guide by installing Node.js with the node-v0.10.9-x64.msi installer. I then started up a cygwin console and cd'd into the directory with my .coffee file. If I type coffee all by itself, it gives me this error:
$ coffee
coffee>
events.js:72
throw er; // Unhandled 'error' event
^
Error: read ENOTCONN
at errnoException (net.js:884:11)
at Socket._read (net.js:389:21)
at Socket.Readable.read (_stream_readable.js:320:10)
at Socket.read (net.js:291:43)
at new Socket (net.js:185:10)
at process.stdin (node.js:660:19)
at new REPLServer (repl.js:132:15)
at Object.exports.start (repl.js:312:14)
at Object.module.exports.start (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\repl.js:106:23)
at Object.exports.run (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:77:32)
at Object.<anonymous> (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\bin\coffee:7:41)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
And if I run the command with -lw it gives me this error:
$ coffee -lw Example.js.coffee
Error: This socket is closed.
at Socket._write (net.js:618:19)
at doWrite (_stream_writable.js:219:10)
at writeOrBuffer (_stream_writable.js:209:5)
at Socket.Writable.write (_stream_writable.js:180:11)
at Socket.write (net.js:596:40)
at lint (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:468:15)
at compileScript (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:193:18)
at C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:144:18
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
And if I run with just the -l option it gives me this error:
$ coffee -l Example.coffee
Error: This socket is closed.
at Socket._write (net.js:618:19)
at doWrite (_stream_writable.js:219:10)
at writeOrBuffer (_stream_writable.js:209:5)
at Socket.Writable.write (_stream_writable.js:180:11)
at Socket.write (net.js:596:40)
at lint (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:468:15)
at compileScript (C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:193:18)
at C:\Users\foo\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:144:18
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
But it seems like I can compile and/or watch option without the lint option and things work as expected.
I don't know anything about Node.js. I've tried googling these errors and I see similar ones related to ports in use and socket issues. I think it might be useful to note that I'm using Intellij IDEA (an IDE) and it has a CoffeeScript plugin which perhaps is interfering. But when I turn Intellij off I still get these same errors so that might be a red herring.
Also, perhaps there's a specific cygwin version of node.js I should have installed instead of the one I got from the installation instructions?
If I type node all by itself, it says this:
$ node
events.js:72
throw er; // Unhandled 'error' event
^
Error: read ENOTCONN
at errnoException (net.js:884:11)
at Socket._read (net.js:389:21)
at Socket.Readable.read (_stream_readable.js:320:10)
at Socket.read (net.js:291:43)
at new Socket (net.js:185:10)
at process.stdin (node.js:660:19)
at startup (node.js:145:16)
at node.js:901:3
Unfortunately, node no longer supports Cygwin.
One workaround is to use some variety of MSysGit as a console instead of Cygwin, at least for running node/coffeescript. Git Bash supplies a good one. You can get it here.

Resources