Skip to content

fix: propagate tsc errors#82

Merged
sxzz merged 9 commits intosxzz:mainfrom
privatenumber:tsc-errors
Aug 14, 2025
Merged

fix: propagate tsc errors#82
sxzz merged 9 commits intosxzz:mainfrom
privatenumber:tsc-errors

Conversation

@privatenumber
Copy link
Contributor

Description

Previously, tsc errors were ignored. Since tsc usually emits files even with type errors, it was possible for .d.ts files that don't pass type-checking to be generated.

This PR ensures that type errors are caught as a build error.

This surfaced errors in existing tests (which is great!), so I updated the tsc call to use the following compilerOptions for dts generation:

  • moduleResolution: "bundler" – most lenient and compatible mode (for bundlers)
  • module: "preserve" – required for bundler mode (es2015+ also works)

Linked Issues

Additional context

@privatenumber privatenumber changed the title Tsc errors fix: propagate tsc errors Aug 13, 2025
src/generate.ts Outdated
Comment on lines +266 to +268
options.tsconfigRaw.compilerOptions ??= {}
options.tsconfigRaw.compilerOptions.module = 'preserve'
options.tsconfigRaw.compilerOptions.moduleResolution = 'bundler'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should overwrite it, since we'll be reading the tsconfig from the user. In some cases, this could lead to unexpected results, as we've seen in previous issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the unexpected results?
FYI I do this in pkgroll and it's been fine: https://github.com/privatenumber/pkgroll/blob/master/src/rollup/configs/dts.ts#L53-L54

Do you prefer we update the tsconfig in the tests instead?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit tricky, see https://stackblitz.com/edit/vitejs-vite-wfsxz95t

image

In general, I’d rather not alter the user’s configuration; if they want this behavior, they can enable it themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this error is technically valid since vue has an export map that disallow importing from vue/jsx-runtime/index.js. But ok, fair enough. Will revert.

src/tsc/index.ts Outdated
Comment on lines +302 to +308
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program)
const errors = preEmitDiagnostics.filter(
(d: ts.Diagnostic) => d.category === ts.DiagnosticCategory.Error,
)
if (errors.length > 0) {
return { error: ts.formatDiagnostics(errors, formatHost) }
}
Copy link
Owner

@sxzz sxzz Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this API time-consuming? At the very least, we should provide an option for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, yes—good catch. It was always running getPreEmitDiagnostics(program) across the entire program.

Now, it runs program.emit() first, and only runs getPreEmitDiagnostics(program) if emitSkipped indicated that there are further errors to collect.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 14, 2025

Open in StackBlitz

npm i https://pkg.pr.new/rolldown-plugin-dts@82

commit: c791318

@sxzz sxzz merged commit ff295ca into sxzz:main Aug 14, 2025
11 checks passed
@privatenumber privatenumber deleted the tsc-errors branch August 14, 2025 04:11
sxzz added a commit that referenced this pull request Aug 25, 2025
@sxzz sxzz mentioned this pull request Aug 25, 2025
7 tasks
privatenumber added a commit to privatenumber/rolldown-plugin-dts that referenced this pull request Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants