Skip to content

[Bug]: esm export * from 'externalized-dep' still generating unnecessary code #1940

@yyx990803

Description

@yyx990803

Reproduction link or steps

https://github.com/rolldown/repros/tree/esm-re-export

// main.js
export * from "x"
// rolldown.config.mjs
export default {
  input: './main.js',
  external: ['x']
}

What is expected?

Output should just be

export * from "x"

What is actually happening?

Output includes tons of unnecessary code:

import "x";

export * from "x"

//#region rolldown:runtime
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
	if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
		key = keys[i];
		if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
			get: ((k) => from[k]).bind(null, key),
			enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
		});
	}
	return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));

//#endregion
//#region main.js
var main_ns = {};
import * as import_x from "x";
__reExport(main_ns, import_x);

//#endregion

Most importantly, the line import * as import_x from "x"; completely breaks treeshaking for any module that imports this one.

System Info

rolldown@nightly (0.12.2-snapshot-a2bb2ca-20240811003152)

Any additional comments?

No response

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions