Skip to content

Namespaces are not disambiguated by star exports #53707

Open
@ghost

Description

Version

v22.4.0

Platform

Linux silica 6.8.0-36-generic #36-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 10 10:49:14 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

loaders

What steps will reproduce the bug?

This set of files reproduces. Execute entry.mjs to observe.

// substance.mjs
export const value = 'Curiouser and curiouser.'
// relay1.mjs
export * as substance from './substance.mjs'
// relay2.mjs
export * as substance from './substance.mjs'
// aggregate.mjs
export * from './relay1.mjs'
export * from './relay2.mjs'
// entry.mjs
import { substance } from './aggregate.mjs'
console.log(substance)

// Firefox:
// Module { value: 'Curiouser and curiouser.' }

// Node.js:
// SyntaxError: The requested module './aggregate.mjs'
// contains conflicting star exports for name 'substance'

This line embeds the above files in a graph of data URLs to reproduce in a snippet. Firefox also succeeds on this one.

node --import 'data:text/javascript;charset=utf-8;base64,aW1wb3J0IHsgc3Vic3RhbmNlIH0gZnJvbSAnZGF0YTp0ZXh0L2phdmFzY3JpcHQ7Y2hhcnNldD11dGYtODtiYXNlNjQsWlhod2IzSjBJQ29nWm5KdmJTQW5aR0YwWVRwMFpYaDBMMnBoZG1GelkzSnBjSFE3WTJoaGNuTmxkRDExZEdZdE9EdGlZWE5sTmpRc1RIbHdlVnBYZUdobFZFVnhUREpXTkdOSE9YbGtRMEZ4U1VkR2VrbElUakZaYms0d1dWYzFhbHBUUW0xamJUbDBTVU5rYTFsWVVtaFBibEpzWlVoUmRtRnRSakpaV0U1cVkyMXNkMlJFZEdwaFIwWjVZekpXTUZCWVZqQmFhVEEwVHpKS2FHTXlWVEpPUTNoaFYwZG9NMWxxVGt0TlJXeElWRzVhYVdKck5IZFRWV2hoWVVkS1NWWnRlRXBTUkVKdVUycENUMDFYVG5SaVNGcHJWMFUxYzFreWJFTmhSMHAwVlZka1drMHhXalZaVm1NMVRWZE5lVlp1YkUxaFYwMDVTbmM5UFNjTkNtVjRjRzl5ZENBcUlHWnliMjBnSjJSaGRHRTZkR1Y0ZEM5cVlYWmhjMk55YVhCME8yTm9ZWEp6WlhROWRYUm1MVGc3WW1GelpUWTBMRXg1Y0hsYVYzaG9aVlJKY1V3eVZqUmpSemw1WkVOQmNVbEhSbnBKU0U0eFdXNU9NRmxYTldwYVUwSnRZMjA1ZEVsRFpHdFpXRkpvVDI1U2JHVklVWFpoYlVZeVdWaE9hbU50Ykhka1JIUnFZVWRHZVdNeVZqQlFXRll3V21rd05FOHlTbWhqTWxVeVRrTjRZVmRIYUROWmFrNUxUVVZzU0ZSdVdtbGlhelIzVTFWb1lXRkhTa2xXYlhoS1VrUkNibE5xUWs5TlYwNTBZa2hhYTFkRk5YTlpNbXhEWVVkS2RGVlhaRnBOTVZvMVdWWmpOVTFYVFhsV2JteE5ZVmROT1VwM1BUMG4nDQpjb25zb2xlLmxvZyhzdWJzdGFuY2Up' --eval ''

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

Always.

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

Different paths to the same module namespace should be disambiguated and load successfully.

disambiguate-namespace


This is the behavior specified in ECMAScript:

The relevant logic is ResolveExport. This line toward the bottom defines the star export / namespace interaction:

3. If resolution.[[BindingName]] is not starResolution.[[BindingName]] and either resolution.[[BindingName]] or starResolution.[[BindingName]] is namespace, return ambiguous.

If either but not both are namespace, it's ambiguous. If both are namespace the end result is to disambiguate and consider them identical.


Node.js does disambiguate values within modules:

disambiguate-value

$ node resolve-value/entry.mjs
Curiouser and curiouser.

Firefox also disambiguates module namespaces. This file succeeds:

<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="./entry.mjs"></script>
  </head>
</html>
Object { value: 'Curiouser and curiouser.' }

What do you see instead?

SyntaxError: The requested module './aggregate.mjs' contains conflicting star exports for name 'substance'

Additional information

There's a GitHub repo here with discussion.

https://github.com/bojavou/disambiguate-namespace

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loadersv8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions