Skip to content
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

Yet Another pnpm / monorepo compilation error question #346

Open
JeongJuhyeon opened this issue Dec 28, 2024 · 3 comments
Open

Yet Another pnpm / monorepo compilation error question #346

JeongJuhyeon opened this issue Dec 28, 2024 · 3 comments

Comments

@JeongJuhyeon
Copy link

JeongJuhyeon commented Dec 28, 2024

Hi, apologies if you're getting tired of this repeated topic.

We're trying to get this tool to work in a monorepo. We have two packages, A and B. A is a server, B is a client for it. A will never be published as a package (it wouldn't make sense, it's a server). B is to be published internally as a package. B uses types imported from A. Our goal is to use dts-bundle-generator as part of publishing B, the entry point of the bundling being B/src/index.ts.

Normally we'd import the types simply using an import such as import type { X } from "A/src/One.js", which is also the way e.g. vscode auto-imports X. When we tried running dts-bundle-generator, depending on the truthiness of followSymlinks, we either saw that

  • (followSymlinks: false): While the initial import was seemingly followed correctly (into One.ts), it would fail when following the imports inside that file. If One.ts from package A has import { f } from './models.js', this results in the error ../A/src/One.ts(2,31): error TS2307: Cannot find module './models.js' or its corresponding type declarations.
  • (followSymlinks: true): It would fail to resolve the things imported by A from external packages. E.g. if A/src/One.ts has import { Kysely } from 'kysely', it would give an error such as ../A/src/One.ts(52,31): error TS2339: Property 'init' does not exist on type 'Kysely' even though it does exist, and tsc/language server compile without errors).

Maybe we were just doing something wrong here? Not sure.

Possible questions:

Why don't you just compile your server package?

  1. The server part will never be published as a package anywhere, it's a server for internal use, so there's no point.
  2. It means that to reflect any updated types in the client when developing, we need to recompile the server, which adds another step to remember and added complexity

Despite the above, we gave compiling A a try. Unfortunately, this did not make it work out of the box, though it did provide a workaround. It appears that to make dts-bundle-generator work, we have to manually change the import path in our files, like so: import type { X } from "A/src/One.js --> import type { X } from "A/dist/One.d.ts.

This does make things work, but isn't great - we now both 1. Have to introduce a compilation step for A and 2. Can no longer auto-import, having to manually rewrite them to A/dist/.../__.d.ts.
We'd like to know if this is the expected behavior or caused by us doing something wrong, and whether there is any better workaround.

Thank you for making this tool!

@timocov
Copy link
Owner

timocov commented Jan 5, 2025

Hey @JeongJuhyeon can you provide a repro I can play with?

@JeongJuhyeon
Copy link
Author

@timocov Will do, just need 0-2 days

@timocov
Copy link
Owner

timocov commented Mar 2, 2025

hey @JeongJuhyeon any update?

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

No branches or pull requests

2 participants