node icon indicating copy to clipboard operation
node copied to clipboard

Namespaces are not disambiguated by star exports

Open ghost opened this issue 2 years ago • 4 comments

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

ghost avatar Jul 03 '24 03:07 ghost

@nodejs/loaders

avivkeller avatar Jul 03 '24 14:07 avivkeller

I just tested this in the browser and it does not work in Chrome - therefore this is a V8 issue.

I'd strongly encourage you to post a Chromium bug here further.

guybedford avatar Jul 03 '24 16:07 guybedford

I'd like to report it but I can't submit there as it requires a Google account.

ghost avatar Jul 03 '24 18:07 ghost

This was fixed upstream in V8 by [modules] Fix re-exporting of module namespaces.

I retested the original reproduction on the latest supported releases:

  • Node.js v26.5.0: succeeds
  • Node.js v24.18.0 and v22.23.1: still throw conflicting star exports

Should this remain open for an LTS backport, or be closed as fixed in Node.js 26?

inoway46 avatar Jul 26 '26 12:07 inoway46