Skip to content

Monorepo Packages are not bundled as expectedΒ #544

@anasmohammed361

Description

@anasmohammed361

Reproduction link or steps

I use turborepo + pnpm workspaces for my project setup , i have been using tsup for my bundles , But migrating to tsdown actually broke the deployment due to certain inconsistencies.

What am i bundling and what is my setup?:

I have my api implemented in hono , and i use few internal packages like @repo/ui , @repo/shared , @repo/drizzle ,
These are small pieces that make up my entire project , generally when deploying i expect these packages to be bundled with my source code of api because i don't transpile those internal ts files for the packages ,i re export them directly , i let the build step of my api transpile those files for me during my build pipelines.

this is my tsup config for reference

import { defineConfig } from "tsup";
export default defineConfig({
  entry: ["src/index.ts"],
  sourcemap: false,
  clean: false,
  minify: false,
  outDir: "tsupdist",
  format: "esm",
  // publicDir:"static",
  noExternal: ["@repo/drizzle", "@repo/shared", "@repo/supabase"],
});

This properly bundles everything and gives me an index.js file where all my internal package are bundled as expected

and i have shared my package.json for reference as well

{
// ...,
"dependencies": {
  //....
    "@repo/drizzle": "workspace:*",
    "@repo/shared": "workspace:*",
    "@repo/supabase": "workspace:*",
    "@scalar/hono-api-reference": "^0.9.10",
    "@supabase/ssr": "catalog:",
    "@supabase/supabase-js": "catalog:",
 //....
}
}

But when i try the same thing with tsdown it is not working as expected

import { defineConfig } from "tsdown";

export default defineConfig({
  entry: ["src/index.ts"],
  sourcemap: false,
  clean: false,
  minify: false,
  outDir: "tsdowndist",
  format: "esm",
  noExternal: ["@repo/drizzle", "@repo/shared", "@repo/supabase"],
});

But the ouput that is generated is not actually accurate the generated index.js is also not accurate , the output code actually has the import statements rather than bundling the @repo/ packages

i am sharing a part of the generated code for reference

import { Hono } from "hono";
import { logger } from "hono/logger";
import { serve } from "@hono/node-server";
import { cors } from "hono/cors";
import "dotenv/config";
import { describeRoute, openAPISpecs } from "hono-openapi";
import { Scalar } from "@scalar/hono-api-reference";
import { jwt } from "hono/jwt";
import { env } from "hono/adapter";
import { createServerClient } from "@supabase/ssr";
import { LivekitService } from "@repo/shared/services/livekit/livekit.service"; // These are not supposed to happen
import { resolver, validator } from "hono-openapi/zod";
import { ClientSingerService } from "@repo/shared/services/client_singer/client_singer.service";
import { WalletService } from "@repo/shared/services/wallet/wallet.service";
//...

Additional Expertiment (If it helps)

Just for confirming i also tried bundling a package that has a actual version , The package that i chose was zod , when i put zod in the noExternal array it just worked as expected.

When skimming around i saw a issue where they said the oxc compiler doesn't support Yarp Pnp workspace:* packages , This might be the case with pnpm as well because pnpm also uses workspace:* for referencing internal packages.

What is expected?

Properly bundle the internal packages and support all types of packages

  • package versions - ^0.6.4
  • catalog versions - catalog:
  • internal workspace packages - workspace:*

Ensure that the tsdown api is functioning similar to the tsup api

What is actually happening?

Instead of transpiling the source code and bundling it with the output , the import statements are preserved for internal packages.

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions