-
-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Describe the bug
The dts generation when processing a declare class type coming from node_modules, that has #private, and somehow ends up moving it to a declare const.
We run into this issue when trying to adopt rolldown for typegen on the sanity package, the reproduction is the minimal reproduction I'm able to create. If I inline the import type {Schema} from '@sanity/schema' class it seems to no longer reproduce, so it looks like it has something to do with how precompiled .d.ts files coming from node_modules is handled.
The stackblits link shows a different error than if you run the repro locally. Locally it shows more of the underlying @babel/parser error:
> RD_LOG=error rolldown -c ./rolldown.config.mjs
ERROR Build failed with 1 error:
[plugin rolldown-plugin-dts:fake-js] ~/projects/rolldown-repro-private-crash/src/createSchema.d.ts:2:4
SyntaxError: Unexpected private name. (2:4)
at constructor (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:367:19)
at TypeScriptParserMixin.raise (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:6627:19)
at TypeScriptParserMixin.parsePropertyName (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:12015:22)
at TypeScriptParserMixin.tsParseTypeMember (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:8247:11)
at TypeScriptParserMixin.tsParseList (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:7901:19)
at TypeScriptParserMixin.tsParseObjectTypeMembers (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:8264:26)
at TypeScriptParserMixin.tsParseTypeLiteral (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:8259:25)
at TypeScriptParserMixin.tsParseNonArrayType (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:8478:106)
at TypeScriptParserMixin.tsParseArrayTypeOrHigher (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:8508:21)
at ~/projects/rolldown-repro-private-crash/node_modules/.pnpm/@babel+parser@7.28.0/node_modules/@babel/parser/lib/index.js:8564:158
at normalizeErrors (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/shared/src-Cs-HV-Wp.mjs:2260:18)
at handleOutputErrors (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/shared/src-Cs-HV-Wp.mjs:2996:34)
at transformToRollupOutput (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/shared/src-Cs-HV-Wp.mjs:2990:2)
at RolldownBuild.write (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/shared/src-Cs-HV-Wp.mjs:4193:10)
at async bundleInner (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/cli.mjs:1598:16)
at async bundleWithConfig (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/cli.mjs:1510:7)
at async main (~/projects/rolldown-repro-private-crash/node_modules/.pnpm/rolldown@1.0.0-beta.31/node_modules/rolldown/dist/cli.mjs:1748:3)
ELIFECYCLE Command failed with exit code 1.Digging into the debugger allowed me to see more of the context for the babel error, and the code it refers to in createSchema.d.ts:2:4 looks like:
export declare const builtinSchema: {
#private: any;
_original: {
name: string;
types: any[];
parent?: /*elided*/ any;
};
_registry: {
[typeName: string]: any;
};
get name(): string;
get parent(): /*elided*/ any | undefined;
get(name: string): any;
has(name: string): boolean;
getTypeNames(): string[];
getLocalTypeNames(): string[];
};Reproduction
https://stackblitz.com/edit/rolldown-repro-private-crash?file=package.json
System Info
System:
OS: macOS 15.4.1
CPU: (16) arm64 Apple M4 Max
Memory: 189.19 MB / 128.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.17.1 - /usr/local/bin/node
npm: 10.9.2 - /usr/local/bin/npm
pnpm: 10.14.0 - /usr/local/bin/pnpm
bun: 1.2.2 - /opt/homebrew/bin/bun
Browsers:
Chrome: 138.0.7204.184
Chrome Canary: 141.0.7340.0
Safari: 18.4
Safari Technology Preview: 26.0Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- The provided reproduction is a minimal reproducible of the bug.