tomayac / local-reverse-geocoder

Local reverse geocoder for Node.js based on GeoNames data
Apache License 2.0
190 stars 58 forks source link

Using typescript-written module within NodeJS #42

Closed prokorpio closed 3 years ago

prokorpio commented 3 years ago

Hi. Thanks for this module, it seems to be very fitting to my use case.

Unfortunately, I can't run the sample usages as I'm encountering a node_module "SyntaxError: Unexpected token ." on the following line:

https://github.com/tomayac/local-reverse-geocoder/blob/575de19336c263d9b6070ebb5aae39a9fc177cd3/index.js#L619

I have looked it up and found that the question mark is used in typescript to mark an optional parameter. As I'm new to JS and not familiar to Typescript, I am wondering, is this module usable in non-typescript JS? If so, is there something I can do to use it as a dependency?

prokorpio commented 3 years ago

Hi, I have found a solution to the problem. Sharing here in case anyone also comes across this error.

Apparently, the operator (?.) that's causing the error is called optional chaining. I have found that only newer versions of nodejs have this enabled by default. I checked my node version and it's v10.19.0 (latest at the time of writing is v14.17.6). This may also be the case for you if you installed node via sudo apt install nodejs.

To fix that, I uninstalled the old nodejs package via sudo apt purge nodejs && sudo apt autoremove, then installed the latest version via nvm.

After that, the reverse-geocoder now works as intended :)

tomayac commented 3 years ago

Thanks for sharing your solution (and sorry for the delay, I don't typically check my open source projects on weekends). I have looked into the code, and it turns out the conflicting line, introduced in https://github.com/tomayac/local-reverse-geocoder/pull/41, wasn't even needed. I have just released v0.11.1 that improves the compatibility with older Node versions.