Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Convert to commonjs for Node #31

Open
dmihal opened this issue May 16, 2020 · 4 comments
Open

Convert to commonjs for Node #31

dmihal opened this issue May 16, 2020 · 4 comments
Labels
ecosystem Concerns related to integration into the broader ecosystem

Comments

@dmihal
Copy link

dmihal commented May 16, 2020

The library uses ES modules, which requires a transpiling with something like babel. Thus, this can't be used easily in Node.js.

@liamzebedee
Copy link
Contributor

Hey @dmihal - we've been developing/testing tbtc.js with some of the latest versions of node (v13), which include native support for ES modules. I believe you still need a flag for the JSON artifacts to load - --experimental-json-modules.

If you have Node v13, running node --experimental-json-modules example.js should work.

@dmihal
Copy link
Author

dmihal commented May 19, 2020

That's probably fine for now since tBTC is still in beta. But long term, limiting the library to only work with an experimental flag will probably prevent a lot of developers from using the library.

I've written a number of NPM libraries, I know how frustrating it is trying to get a library to play nicely with both Web/Babel & Node 😩

@liamzebedee
Copy link
Contributor

liamzebedee commented May 20, 2020

I know how frustrating it is trying to get a library to play nicely with both Web/Babel & Node 😩

Oh, I agree @dmihal, it's a nightmare. Sourcemaps in particular are something that still scare me re: transpilation.

I don't know so much about bundling, aside from the requirements varying between every system I've used (Next.js, create-react-app, webpack, the list goes on). That being said - we should be able to make this usable from the get-go. I think in the coming weeks we'll explore some approaches, and if you have any recommendations, please feel free to contribute them. 🙂

@liamzebedee liamzebedee added enhancement New feature or request bug Something isn't working labels May 20, 2020
@Shadowfiend Shadowfiend removed bug Something isn't working enhancement New feature or request labels May 20, 2020
@Shadowfiend
Copy link
Contributor

No current plans to convert away from ES modules here, so I dropped the tags in favor of an ecosystem tag---we use ES modules expectedly and intentionally, but a switch away from them might be dictated by ecosystem concerns.

To elaborate a bit, the decision to use ES modules was rooted in the goals of running on recent versions of Node, working for modern browser versions, and not requiring babel, while still supporting a relatively modern development environment. This is why all typing is done in JSDoc rather than TypeScript, for example. The fact that node currently tucks this behind a flag is annoying, but note that if an npm package is marked as type: "module", recent versions of Node, including the latest LTS version, should handle things transparently, and all bin/ scripts have a shebang that specifies the appropriate flag.

We're open to feedback on specific trip-ups folks have integrating here, and definitely open to convert back to standard CommonJS if the downsides prove too great.

@Shadowfiend Shadowfiend added the ecosystem Concerns related to integration into the broader ecosystem label May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ecosystem Concerns related to integration into the broader ecosystem
Projects
None yet
Development

No branches or pull requests

3 participants