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

[Bug]: duplicated default import #3199

Closed
nstepien opened this issue Dec 22, 2024 · 4 comments · Fixed by #3205
Closed

[Bug]: duplicated default import #3199

nstepien opened this issue Dec 22, 2024 · 4 comments · Fixed by #3205
Assignees
Labels
bug Something isn't working

Comments

@nstepien
Copy link

Reproduction link or steps

Repo branch: adazzle/react-data-grid#3578

  • git clone https://github.com/adazzle/react-data-grid.git
  • git checkout rolldown
  • npm i
  • npm run build
  • open lib/bundle.js
  • notice that that the default export of clsx is imported multiple times with different identifiers
    import clsx, { default as clsx$1, default as clsx$2, default as clsx$3, default as clsx$4, default as clsx$5, default as clsx$6, default as clsx$7 } from "clsx";

What is expected?

I'd expect the following import to not result in multiple imports.

import clsx from "clsx";

What is actually happening?

The clsx default export is imported under multiple identifiers.

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (64) x64 AMD Ryzen Threadripper 3970X 32-Core Processor
    Memory: 11.11 GB / 31.88 GB
  Binaries:
    Node: 23.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 11.0.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.99)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    rolldown: ^0.15.1 => 0.15.1

Any additional comments?

The CJS output (lib/bundle.cjs) does not have this issue.
Rollup does not have this issue either.

@nstepien nstepien added bug Something isn't working needs-triage labels Dec 22, 2024
@hi-ogawa
Copy link
Member

I made a minimal-ish repro https://stackblitz.com/edit/github-ugpzvon2?file=src%2Fentry.js

Esbuild also doesn't dedupe same external imports (though in a different way) esbuild try and there's an issue about it evanw/esbuild#475

@nstepien
Copy link
Author

Other external imports don't exhibit this behavior in my build, that's odd. 🤔

import { createContext, forwardRef, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
import { flushSync } from "react-dom";
import clsx, { default as clsx$1, default as clsx$2, default as clsx$3, default as clsx$4, default as clsx$5, default as clsx$6, default as clsx$7 } from "clsx";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";

Maybe it's only an issue with default imports?

@hi-ogawa
Copy link
Member

Indeed, this seems to only happen for default import. I updated the repro above now output looks like this:

import externalDefault, { externalNamed, default as externalDefault$1 } from "external";

//#region src/dep.js
var dep_default = "dep";
console.log({
	externalDefault: externalDefault$1,
	externalNamed
});

//#endregion
//#region src/entry.js
console.log({
	externalDefault,
	externalNamed,
	dep: dep_default
});

//#endregion

@IWANABETHATGUY IWANABETHATGUY self-assigned this Dec 23, 2024
@hyf0
Copy link
Member

hyf0 commented Dec 23, 2024

Seems default doesn't get merged on purpose @IWANABETHATGUY cc

if name.as_str() != "default" {
self
.external_import_binding_merger
.entry(rec.resolved_module)
.or_default()
.entry(name.inner().clone())
.or_default()
.insert(*imported_as_ref);
}

@hyf0 hyf0 removed the needs-triage label Dec 23, 2024
github-merge-queue bot pushed a commit that referenced this issue Dec 23, 2024
<!-- Thank you for contributing! -->

### Description
1. part of #3199
2. will try to merge two `external` default import if they are in same
chunk
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants