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

Importing fs constants in node:fs/promises throws an error #45234

Closed
kapekost opened this issue Oct 29, 2022 · 9 comments
Closed

Importing fs constants in node:fs/promises throws an error #45234

kapekost opened this issue Oct 29, 2022 · 9 comments
Labels
doc Issues and PRs related to the documentations.

Comments

@kapekost
Copy link

kapekost commented Oct 29, 2022

Affected URL(s)

https://nodejs.org/api/fs.html#fspromisesaccesspath-mode

Description of the problem

import { access, constants } from 'node:fs/promises';

the above constants seems to be badly exported. As a workaround one can import * from 'node/fs

@kapekost kapekost added the doc Issues and PRs related to the documentations. label Oct 29, 2022
@mscdex
Copy link
Contributor

mscdex commented Oct 29, 2022

What is the error that is thrown?

@Trott
Copy link
Member

Trott commented Oct 29, 2022

It works fine for me in Node.js 18 and 19. What version are you using?

@Trott
Copy link
Member

Trott commented Oct 29, 2022

Works in Node.js 16 as well. It does not work in Node.js 14 but the documentation for 14.x doesn't include that, so it seems like all supported releases are working as expected.

@kapekost
Copy link
Author

must be the version, I was under the impression I defaulted 19 just before that, but apparently I am still on 17..
something is not working ok with nvm use 19 command on windows :(
works ok with node v19 on a container

import { access, open, constants } from 'node:fs/promises';
                       ^^^^^^^^^
SyntaxError: The requested module 'node:fs/promises' does not provide an export named 'constants'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:127:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:331:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

C:>node -v
v17.2.0

@Trott
Copy link
Member

Trott commented Oct 30, 2022

Yeah, 17.x doesn't work with this. 17.x is also no longer supported as of about 5 months ago. So, yeah, try updating to 18.x and it should work.

@Trott Trott closed this as completed Oct 30, 2022
@Trott
Copy link
Member

Trott commented Oct 30, 2022

Pinging @nodejs/version-management in case anyone wants to offer suggestions or try to troubleshoot @kapekost's possible issue with nvm for Windows.

@coreybutler
Copy link
Member

@kapekost - please see coreybutler/nvm-windows#708.

For anyone landing here from Google, NVM4W 1.1.8 and below requires the full version, i.e. nvm install 19.0.0. In NVM4W 1.1.9 and above, you can use nvm install latest, nvm install lts, etc. See the repo for details.

@kapekost
Copy link
Author

Thanks! Looks lime the older NVM version on windows, was reporting a successful switch to nodejs 19, and it was digesting a permission error. It worked ok after upgrading that to latest, and run as admin

@Caroylina

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations.
Projects
None yet
Development

No branches or pull requests

5 participants