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

Namespaces are not disambiguated by star exports #53707

Open
bojavou opened this issue Jul 3, 2024 · 3 comments
Open

Namespaces are not disambiguated by star exports #53707

bojavou opened this issue Jul 3, 2024 · 3 comments
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders v8 engine Issues and PRs related to the V8 dependency.

Comments

@bojavou
Copy link

bojavou commented Jul 3, 2024

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

@RedYetiDev RedYetiDev added loaders Issues and PRs related to ES module loaders esm Issues and PRs related to the ECMAScript Modules implementation. labels Jul 3, 2024
@RedYetiDev
Copy link
Member

@nodejs/loaders

@mcollina mcollina added the confirmed-bug Issues with confirmed bugs. label Jul 3, 2024
@guybedford
Copy link
Contributor

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.

@RedYetiDev RedYetiDev added the v8 engine Issues and PRs related to the V8 dependency. label Jul 3, 2024
@bojavou
Copy link
Author

bojavou commented Jul 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders v8 engine Issues and PRs related to the V8 dependency.
4 participants