I encountered this issue while applying tsup to my project, and I'll show you a simple code example that you can reproduce.
I have two source files.
// src/index.ts
import func from "./func";
export default function run() {
return func;
}
// src/func.ts
export default class func {}
I use the build command like this tsup src --clean --dts. In this case, the build result is index.js, which looks like this:
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
default: () => run
});
module.exports = __toCommonJS(src_exports);
// src/func.ts
var func = class {
};
// src/index.ts
function run() {
return func;
}
The func class is also included in the build output, func.js. Because of this, the func class in the return value of run in index.js and the func class in the func.js file will be different values, causing my test to fail.
If I replace index.ts and func.ts with js extensions and run them with tsx to test, I don't have this problem. I'm wondering if this is intended and if not, if there is a way to work around it.
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
We receive the funding once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
I encountered this issue while applying tsup to my project, and I'll show you a simple code example that you can reproduce.
I have two source files.
I use the build command like this
tsup src --clean --dts
. In this case, the build result is index.js, which looks like this:The func class is also included in the build output, func.js. Because of this, the func class in the return value of run in index.js and the func class in the func.js file will be different values, causing my test to fail.
If I replace index.ts and func.ts with js extensions and run them with tsx to test, I don't have this problem. I'm wondering if this is intended and if not, if there is a way to work around it.
Upvote & Fund