Skip to content

By using npm add to add the pkg, the esm project cannot import the functions of pkg by name, but it can do so using the file protocol. #56286

@shlroland

Description

@shlroland

Version

v22.9.0

Platform

Darwin Mac-mini.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:36:26 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8103 arm64

Subsystem

No response

What steps will reproduce the bug?

related repo https://github.com/Callidon/bloom-filters

When I added this bloom-filters CJS package to my ESM project, I could not import the named functions of this package by name, and could only use the default import.

steps for reproduction:

  1. this is reproduction code: bloom-filters.zip
  2. Enter the demo_test directory and execute yarn to install dependencies. At this time, bloom-filters is pulled in by npm.
  3. When you run node index.js, you'll notice that all the named functions exported by the package are located on the default object except for the MinHash method.
Image
  1. Now, let's import the bloom-filter as a file protocol.
Image
  1. Then run node index.js
    Image

  2. As shown in the figure above, all named functions in bloom-filter have appeared on the module object and default object.

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

My expectation is that the bloom-filter pulled from npm can also import named functions.
Just like what is said in the document https://nodejs.org/docs/latest-v22.x/api/esm.html#commonjs-namespaces

What do you see instead?

As I have described.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    wrong repoIssues that should be opened in another repository.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions