Skip to content

Yet Another pnpm / monorepo compilation error question #346

@JeongJuhyeon

Description

@JeongJuhyeon

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions