# npm pathwatcher module for Meteor fails



## cfw (Nov 2, 2015)

I'm trying to get Meteor to run on FreeBSD and thanks to Tom Hardenberg's https://github.com/4commerce-technologies-AG/meteor there is a good chance of getting it working.

Unfortunately the pathwatcher npm module is currently a showstopper.

`npm install pathwatcher`

builds fine as long as gmake is available but trying to load pathwatcher inside `node`


```
var p = require('pathwatcher');
```
fails with:

```
node_modules/pathwatcher/build/Release/pathwatcher.node: Undefined symbol "_Z12PlatformInitv"
```

Does anyone know what's going on here?


----------



## olivierd (Nov 2, 2015)

cfw said:


> I'm trying to get Meteor to run on FreeBSD and thanks to Tom Hardenberg's https://github.com/4commerce-technologies-AG/meteor there is a good chance of getting it working.
> 
> Unfortunately the pathwatcher npm module is currently a showstopper.
> 
> ...



I could be wrong, but support of FreeBSD is not present in binding.gyp.

Try to patch this file, at line *41* replace the following code:


```
'OS=="mac"',
```

by


```
'OS=="mac" or OS=="freebsd"',
```

We also use kqueue(2)/kevent for events monitoring.

In the latest status report (from July to September) I mention, that I'm working on new USES framework in order to easily install Node.js modules (a kind of `npm -g install`).


----------



## TomFreudenberg (Nov 2, 2015)

Hi olivierd

Thanks for guiding us in this issue. Makes totally sense to add also a file for freebsd FreeBSD ;-) Unfortunately I can't get it to work.

We need Release @4.1.0 from https://github.com/atom/node-pathwatcher, but I also tried latest release @6.2.4 - all the time now I got this error:


```
Error: Cannot find module 'pathwatcher'
```

What I use: node v0.10.40 and npm v1.4.28

What I did:


```
mkdir -p /tmp/test-pathwatcher
cd /tmp/test-patchwatcher
git clone -b v6.2.4 https://github.com/atom/node-pathwatcher
vi node-pathwatcher/binding.gyp (just changed mac to freebsd)
npm install ./node-pathwatcher
echo "var p = require('pathwatcher');" > demo.js
node demo.js

>>>> Error: Cannot find module 'pathwatcher'
```

Do you have any additional tips?


----------



## olivierd (Nov 2, 2015)

TomFreudenberg said:


> Hi olivierd
> 
> thanks for guiding us in this issue. Makes totally sense to add also a file for freebsd ;-)
> 
> ...



Personally when Node module is written in CoffeeScript I avoid to clone repository, because:

`coffee` must be in your $PATH

NODE_PATH variable must be defined
Simply download tarball from https://www.npmjs.com/. For pathwatcher, the url is
http://registry.npmjs.org/pathwatcher/-/pathwatcher-6.2.5.tgz It already contains compiled  JavaScript module.

Pathwatcher requires also node-gyp in order to build C++ code (it can be installed with npm, or using my experimental repository if you use the ports tree). Others modules are also necessary.

`node-gyp` must also defined some environments variables (if it uses globally, see Mk/Uses/nodegyp.mk for more details).

Pure JavaScript modules are easy to install with `npm`, but when they contain extensions written in C (or C++) is more difficult.

Quick and dirty method in order to install pathwatcher:
1. `npm install pathwatcher` (dependencies will be installed)
2. Remove this particular module, search hidden directory in your $HOME
3. Download tarball from NPM registry
4. Patch binding.gyp
5. Configure and build the pathwatcher extension via `node-gyp`
6. Install module with the others (in your $HOME

I think node-gyp should also be fixed especially addon.gypi for headers.


----------



## TomFreudenberg (Nov 3, 2015)

Hi olivierd

You make my day! and guide me again to the right direction 

A big issue was that the base file was named pathwatcher_mac.mm which took me a few moments to realize that gmake() ignores it ;-)

So I renamed that to pathwatcher_mac.cc just to test.

The compiler spite out some undefined DEFINES so I copied the file from mac to freebsd and added two defines


```
#define F_GETPATH       50              /* return the full path of the fd */
#define O_EVTONLY       0x8000          /* descriptor requested for event notifications only */
```

I took them from http://fxr.watson.org/fxr/source/bsd/sys/fcntl.h?v=xnu-792.6.70 what is hopefully correct.

After that I added a section for freebsdFreeBSD to the bindings.gyp and rebuild and ...

YEAH it works

I will setup a github repo for that to allow others to run that stuff without too much headache.

Thanks a lot for your guidiances!

Tom


----------



## TomFreudenberg (Nov 3, 2015)

Hi olivierd

One question left: If I want to provide a patch to original repo including the coffee files, what is necessary that this may run as well?

On uploading to npmjs will those files (automatically) converted to pure js or why are the files on npmjs are different to the source repo?

Thanks for any comment in advance
Tom


----------



## TomFreudenberg (Nov 3, 2015)

Hi olivierd - I got that already as well

There is a task "grunt prepublish" which will run if all the grunt stuff is installed and that builds a correct package

Thanks again, now I am done



Tom


----------



## olivierd (Nov 3, 2015)

TomFreudenberg, I don't, how npmjs works 

Perhaps, if you send diff or open an issue to maintainer of node-pathwatcher, new release will be available for users.


----------



## TomFreudenberg (Nov 3, 2015)

Hi olivierd

Yes, I send him a PR - If I am right, it is maintained by Github / Atom


----------



## TomFreudenberg (Nov 4, 2015)

Hi olivierd, last message to this thread:

My changes are already merged and published from maintainer to a new npm release for pathwatcher 

https://github.com/atom/node-pathwatcher/commits/v6.3.0

Great process!


----------

