Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Support #81

Closed
dscape opened this issue May 17, 2020 · 4 comments
Closed

Require Support #81

dscape opened this issue May 17, 2020 · 4 comments

Comments

@dscape
Copy link

dscape commented May 17, 2020

Was trying to use the module in node.js but couldn't require it. Ended up installing version 1.1 from npm to circumvent this issue.

Any specific reason not to support require?

@chrisveness
Copy link
Owner

Version 2 of the geodesy library was a significant development, including adding modern reference frames in addition to traditional datums, and refactoring & extending n-vector functions. I had to use ES6 modules to achieve the new functionality due to the more complex interdependencies.

You're welcome to continue using version 1.

What is the reason you don't want to use import? I no longer find I need to use require() at all!

@dscape
Copy link
Author

dscape commented May 20, 2020

Hi @chrisveness – I haven't coded in 7 years and I haven't caught up with the differences yet. Also I don't do client side development so have no need for any of such features, in the server it actually makes code a bit less easy to read to have a mixture of requires and imports.

Why would something import but not work with require? can't you simply module.export it if module exists? Thanks for the prompt reply and amazing work, this works incredibly well. I was able to code a simple way to snap my runs to a route in a couple of hours of work!! Thank you

@chrisveness
Copy link
Owner

ES modules (using export/import statements) is the standardised native way of specifying modules (c39.es/ecma262/#sec-modules). Node.js is transitioning from CommonJS to ES modules (nodejs.org/api/esm.html).

Unfortuntely, ESM is generally incompatible with CommonJS (which uses module.exports/require()) – something of a headache for Node.js developers!

However, ESM has many advantages over CommonJS (static, asynchronous, isomorphic, etc), and is certainly the future for JavaScript. exploringjs.com/es6/ch_modules.html has good information.

Saying that, you should be able to use dynamic import to include ES module files from CommonJS code, though I've not tried it myself: nodejs.org/api/esm.html#esm_import_expressions.

@dscape
Copy link
Author

dscape commented May 24, 2020

Thanks Chris. Still strange not being able to require something you npm installed, definitely an anti-pattern. Appreciate all the feedback hopefully other with the same issue will know the solution is to use version 1.1.3!

@dscape dscape closed this as completed May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants