镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Can’t import stream promises API with ECMAScript Modules #35731

Description

@alexewerlof
  • Version:

v12.17.0 (current LTS)
v14.14.0 (LTS in a few days)

  • Platform:

Linux 5.4.0-51-generic

  • Subsystem:

'stream'

What steps will reproduce the bug?

The documentation says:

The stream/promises API provides an alternative set of asynchronous utility functions for streams that return Promise objects rather than using callbacks. The API is accessible via require('stream/promises') or require('stream').promises.

Which is fine. However, when using the ESM syntax it does not work like other APIs like 'fs' or 'dns':

import { promises as fsPromises } from 'fs' // no error thrown
import { promises as dnsPromises } from 'dns' // no error thrown
import { promises as streamPromises } from 'stream'
//       ^^^^^^^^
// SyntaxError: The requested module 'stream' does not provide an export named 'promises'
//     at ModuleJob._instantiate (internal/modules/esm/module_job.js:98:21)
//     at async ModuleJob.run (internal/modules/esm/module_job.js:143:5)
//     at async Loader.import (internal/modules/esm/loader.js:165:24)
//     at async Object.loadESM (internal/process/esm_loader.js:68:5)

What is the expected behavior?

It should work just like 'fs' or 'dns' promises.

This issue is similar to #21014 or the fix in #32953

What do you see instead?

Throws a SyntaxError.

Additional information

I have made a repo to demonstrate the issue. There are various syntaxes, but 2.js shows the issue pretty well.

Activity

  1. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    streamIssues and PRs related to Node.js streams.
    on Oct 21, 2020
  2. ExE-Boss commented on Oct 24, 2020

    @ExE-Boss
    Contributor

    This is because the Stream Promises API is only available from v15.0.0: #33991

  3. markddrake commented on Oct 26, 2020

    @markddrake

    The documentation and version history for streams should make this clear

  4. ExE-Boss commented on Oct 27, 2020

    @ExE-Boss
    Contributor

    #34002 updated the documentation, now it’s just a matter of waiting for the website to be updated.

  5. ctavan commented on Dec 10, 2020

    @ctavan
    Contributor

    This is mentioned on the website now: https://nodejs.org/dist/latest-v15.x/docs/api/stream.html#stream_streams_promises_api

    image

    I believe the issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions