tomayac / local-reverse-geocoder

Local reverse geocoder for Node.js based on GeoNames data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using typescript-written module within NodeJS

prokorpio opened this issue · comments

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:

if (options?.country) {

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?

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 :)

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 #41, wasn't even needed. I have just released v0.11.1 that improves the compatibility with older Node versions.