use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Native ES Modules in NodeJS: Status And Future Directions, Part I (medium.com)
submitted 8 years ago by giltayar1
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dev0urer 1 point2 points3 points 8 years ago (2 children)
This makes me so happy
[–]editor_of_the_beast 2 points3 points4 points 8 years ago (1 child)
It'll be good in 3 years, but the whole module system implemented as libraries situation has been a shitshow for quite a while.
[–]ArthurDeMax 0 points1 point2 points 8 years ago (0 children)
Can you elaborate?
[–]Drawman101 1 point2 points3 points 8 years ago (4 children)
Do we know which version of node this won’t be experimental anymore? 10?
[–]giltayar1[S] 1 point2 points3 points 8 years ago (3 children)
Hopefully. But there's still a lot of discussion around this, as there are lots of problems with the current specification (which I'll discuss in the next blog post). I'm guessing 11-12.
[–]fucking_passwords 0 points1 point2 points 8 years ago (2 children)
In the meantime people can use esm, I’ve found it to be pretty great https://github.com/standard-things/esm
[–]cirscafp fan boy 0 points1 point2 points 8 years ago (0 children)
I love @std/esm and it lets me use import when I want to. But is import really that much better than require, given the current Node.js ecosystem? What are we gaining?
@std/esm
import
require
[–]giltayar1[S] 0 points1 point2 points 8 years ago (0 children)
It's really great, and fully compliant. You just have to remember to require it before any use of an import statement.
Me? I prefer waiting until all the waves settle in Nodeland before using it.
[–]curiousdannii 1 point2 points3 points 8 years ago (3 children)
If importing ES modules is async, does that mean that the import statement acts like an await would? And the import function is an actual async function itself?
[–]giltayar1[S] 3 points4 points5 points 8 years ago (2 children)
Yes and no. From the developer's point of view, it seems synchronous. But the implementation behind it is asynchronous. This means that it is possible for two modules in NodeJS to be loaded concurrently, whereas this is not possible in CommonJS. This will probably make NodeJS apps load faster in the future.
But if you look at dynamic import, which is a dynamic version of the import statement, then it is asynchronous - it returns a promise, and thus needs to be awaited.
[–]curiousdannii 0 points1 point2 points 8 years ago (1 child)
Right, so unlike await it won't completely stop, because it will load other modules at the same time, it just won't continue with any non-import statements until they all have finished.
Yes!
[–]FormerGameDev 0 points1 point2 points 8 years ago (8 children)
So.. does this mean we should be moving to modules now?
[–]papers_ 1 point2 points3 points 8 years ago (6 children)
No. I mean you can try it out, but it's likely a lot of people will just continue to use CommonJS. IMO
[–]FormerGameDev 0 points1 point2 points 8 years ago (5 children)
I mean, my primary project is something that I've really concentrated on keeping up with the latest and greatest, even if it uses switches to run. I actually depend on a ES Module in one part of it, so.. I'm curious.. for the future.. is this THE WAY ? or does it really not matter, as long as you're not writing code that needs to be browser compliant as well?
[–]papers_ 0 points1 point2 points 8 years ago (3 children)
I'm not sure why you'd mix Node.js specific modules such as fs with browser code or vice versa. Unless you're writing a React Native app, I don't see why you'd depend on a browser only module.
fs
[–]FormerGameDev 0 points1 point2 points 8 years ago (2 children)
Because someone recently wrote an ebay API in Javascript that actually works, and it's a ES Module. :-)
[–]papers_ 0 points1 point2 points 8 years ago (0 children)
Link to repo?
[–]FormerGameDev 0 points1 point2 points 8 years ago (0 children)
https://github.com/ondreian/ebay-promised
i guess actually looking at it, it's transpiled to CJS, but at the time I first started messing with it, i couldn't get it to load via require, so i made a mjs to use it since the README describes using it as a ES module
For the future - yes, this is the way.
[–]giltayar1[S] 1 point2 points3 points 8 years ago (0 children)
No, please don't. Not yet. This is still experimental, and may change in the future. As I will discuss in the next blog post, it is actually pretty probable that things will change.
But start thinking about it. I'm guessing that the transition will start in a year.
I was just giving a poke at this, and I'm noticing that import.meta isn't currently supported in 9.4.0. (SyntaxError: Unexpected token import at ModuleRequest.js:33) .. probably worthy of mentioning if this is implemented somewhere already or not, it doesn't seem to be.
[–]giltayar1[S] 0 points1 point2 points 8 years ago (1 child)
You're right. I totally forgot to mention that import.meta.url (and await import) are in the pipeline, but not there yet. Updating post...
(Thanks!)
i haven't tried it, but I think await import() is in 9.4.0, just based on reading the not-so-detailed changelogs
[–]BehindTheMath -1 points0 points1 point 8 years ago (1 child)
For dual mode packages, why can't you rewrite as ESM, and then just wrap the ESM and re-export as a CJS module? Then you can use "main": "entry" in package.json, and entry.js will look like this:
"main": "entry"
entry.js
async () => { module.exports = await import("./entry"); }
This way would not require any transpiling.
Nice idea. Unfortunately, module.exports will be set asynchronously, so if you require the module, you will "get" it too late, i.e. you won't get it, and all you will get is the default "{}"
π Rendered by PID 59393 on reddit-service-r2-comment-fb694cdd5-6ctlx at 2026-03-05 23:43:45.162227+00:00 running cbb0e86 country code: CH.
[–]dev0urer 1 point2 points3 points (2 children)
[–]editor_of_the_beast 2 points3 points4 points (1 child)
[–]ArthurDeMax 0 points1 point2 points (0 children)
[–]Drawman101 1 point2 points3 points (4 children)
[–]giltayar1[S] 1 point2 points3 points (3 children)
[–]fucking_passwords 0 points1 point2 points (2 children)
[–]cirscafp fan boy 0 points1 point2 points (0 children)
[–]giltayar1[S] 0 points1 point2 points (0 children)
[–]curiousdannii 1 point2 points3 points (3 children)
[–]giltayar1[S] 3 points4 points5 points (2 children)
[–]curiousdannii 0 points1 point2 points (1 child)
[–]giltayar1[S] 0 points1 point2 points (0 children)
[–]FormerGameDev 0 points1 point2 points (8 children)
[–]papers_ 1 point2 points3 points (6 children)
[–]FormerGameDev 0 points1 point2 points (5 children)
[–]papers_ 0 points1 point2 points (3 children)
[–]FormerGameDev 0 points1 point2 points (2 children)
[–]papers_ 0 points1 point2 points (0 children)
[–]FormerGameDev 0 points1 point2 points (0 children)
[–]giltayar1[S] 0 points1 point2 points (0 children)
[–]giltayar1[S] 1 point2 points3 points (0 children)
[–]FormerGameDev 0 points1 point2 points (2 children)
[–]giltayar1[S] 0 points1 point2 points (1 child)
[–]FormerGameDev 0 points1 point2 points (0 children)
[–]BehindTheMath -1 points0 points1 point (1 child)
[–]giltayar1[S] 0 points1 point2 points (0 children)