-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Can’t import fs Promises API with ECMAScript Modules #21014
Comments
it's an experimental API so the esm loader doesn't attach it as a named export. |
@dieulot I'm going to close this issue since has been answered. Feel free to ping back though for anything. |
Ideally I could: The opening ask would be only mildly ghastly & ugly, getting a complete 'fs' import. |
the original design of fs promises was as you mention it. I'm hopeful it can be restored. |
Talked with @jdalton some on twitter. He's intending to switch his standard-things/esm project over to exposing non-enumerable properties. This won't make |
@jdalton I'm using Node 10.16.0 and this still doesn't work for me. Trying the following:
or
or
all doesn't work for me. Since I need to specify |
|
Unfortunately, in TS, ES6, ESLint, await/async land with Still waiting on something as simple as
or
or best yet,
|
we still need a better way to do this |
I may be missing something but: import { promises as fs } from 'fs'; isn't good enough? |
@robbie-mac it's OK, but not the best.
would be ok. The former needs node to start using the package exports mentioned here in Not sure how code modules/libs work though. |
@devsnek does node team have another tentative date for From what I see, we are very far from having a safe ESM import model: does this mean node will have the My concern is that due to the flag, the libraries authors aren't willing to adapt and implement "package exports" and thus the flag is stopping the whole environment from moving onwards to ESM: Because we gotta be honest and admit that without the package exports in place, |
also, it is good that people weren't implementing anything until the flag was removed. |
ECMAScript Modules default support landed in 13.2.0 https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V13.md#13.2.0 |
So, what's the answer? Maybe just export promise based versions as |
The standard pattern I’ve seen projects follow is I’m not sure there will be a better way to do this anytime soon. That would involve some alternative for |
@GeoffreyBooth |
If #31553 is merged you will be able to do |
what about |
#32953 is the PR for |
This works now: import fs from 'node:fs/promises' |
Per the docs, “The API is accessible via
require('fs').promises
.”When using ECMAScript Modules it can’t be accessed like that. One may expect to be able to load it with
import {promises as fs} from 'fs'
, but this gives an error.So right now accessing the fs Promises API directly when using ECMAScript Modules requires two lines, like so:
The text was updated successfully, but these errors were encountered: