-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
dts
creation impossibly slow.
#945
Comments
Hey @datner, did you ever find a solution to this? I am encountering the same issue now that my project has reached a certain size and too am running into a (flaky, but always slow) out-of-memory error when enabling |
@coopbri I have not, I went down a rabbit hole of horrors and became a One day the pain will go away.... |
Haha, no worries man! Thanks for detailing your process. I think I'll do much of the same for now ( |
@coopbri word of advice, set up self-imports if you want to bundle to esm and cjs since esm requires you used named imports or full paths (with extensions ) and cjs wants named imports and forbids extensions import * as Foo from './Foo.js' // <-- breaks cjs
import * as Foo from './Foo' // <-- breaks esm
import * as Foo from "my-lib/Foo" // works for both |
Geat tip! Thank you!! |
@datner you may have seen this already, but I'm keeping a close eye on it: https://github.com/dudykr/stc (some discussion at swc-project/swc#657) As an avid SWC fan, I'm really excited for this! |
@coopbri I'm quite satisfied with the performance of That said, I also like swc and have seen this project. It has nothing to see so I didn't know it was usable, I'll give it another glance. Thanks! |
I have the same issue, dts does an out-of-memory, although it's a quite simple expressjs server where tsc has no issue generating types... |
This might be somewhat related to #920 (comment) and may have been fixed upstream in Node v21 and above, particularly if the heap was allocated using slower memory pages from swap. Can someone please test and confirm if this is the case? |
Hey, I just figure out a new solution to address the memory/slowlyness problem. Instead of using the standard tsup config, we use the javascript api with a custom glob in order to chunk the source files, we use the regular tsup build for the build, then for import fs from "node:fs/promises";
import { glob } from "glob";
import { build } from "tsup";
function chunkArray(array, size) {
const chunked_arr = [];
let index = 0;
while (index < array.length) {
chunked_arr.push(array.slice(index, size + index));
index += size;
}
return chunked_arr;
}
async function main() {
try {
await fs.rmdir("dist");
} catch {
console.warn("No dist folder found");
}
const files = await glob("src/components/*/index.tsx", {
withFileTypes: true,
ignore: [
"src/**/*.test.{ts,tsx}",
"src/**/*.spec.{ts,tsx}",
"src/**/*.stories.{ts,tsx}",
],
});
const components = files.map((p) => p.parent?.name);
console.log("[1/2] Building components");
await build({
format: ["esm"],
dts: false,
clean: true,
sourcemap: true,
target: "es2022",
external: ["react", "react/jsx-runtime", "react-dom"],
treeshake: true,
minify: true,
tsconfig: "tsconfig.build.json",
entry: [
"src/index.ts",
"src/**/*@(ts|tsx)",
"!playwright",
"!src/**/*.spec.*",
"!src/**/*.test.*",
"!src/__tests__/**/*",
"!src/**/*.stories.*",
"!fixture",
],
});
console.log(
`[2/2] Building declaration files for ${components.length} components`,
);
const matrix = chunkArray(components, 15);
for (const group of matrix) {
await build({
// same config as the precedent one
dts: {
only: true,
},
tsconfig: "tsconfig.build.json",
entry: group.flatMap((dir) => [
`src/components/${dir}/**/*.{tsx,ts}`,
`!src/components/${dir}/*.test.{tsx,ts}`,
`!src/components/${dir}/*.spec.{tsx,ts}`,
`!src/components/${dir}/*.stories.{tsx,ts}`,
"!fixture",
]),
});
}
}
main(); |
I've been trying to migrate some project from
unbuild
totsup
.Theres nothing special about it, it's not that big either.
unbuild
was pretty fast, with 2-3s to chew the whole thing. dts included.I've moved to
tsup
. bundling was amazingly fast, less than 60ms. Butdts
takes 5 seconds.I do not resolve, it's a plain
dts: true
.I've looked at the
rollup-plugin-dts
and saw that they the following:Ok, so lets do that. I run
tsc
with declaration: true, without a declaration map. It takes around 1s and done.Now tsup takes around 20s to run dts before saying it's out of memory.
I thought there might be some multiple entry points shenanigans, so I tried reducing to only 1 entry point.
dts with no prior
tsc
- 1s. Relatively slow, but fine.dts with
tsc
- crash after 20s. OOM.dts with
tsc
only on the entry file - now dts takes 11s but resolves.... with the same exact result as it would if I haven't generated thed.ts
beforehand.How can this be? Why would it make things worse??
How can
unbuild
do it so fast with the same exact plugin, less optimized??? (they don't disable anything like tsup does)I know this is a general typescript issue, but somehow
tsup
turns a slow operation into a full-on odyssey.Possibly related issues: #840
I tried to work on this on my own, but I couldn't find the source of the issue.
Upvote & Fund
The text was updated successfully, but these errors were encountered: