#Cannot build DTS because using AWS S3 Client

17 messages · Page 1 of 1 (latest)

modern sedge
#

/packages/studio imports /packages/trpc, meaning trpc is built first, studio second. When building trpc alone - it works fine, meanwhile building studio fails on DTS stage, meaning the built JS is alright. the studio's build error says

src/trpc.ts(4,14): error TS2742: The inferred type of 'trpc' cannot be named without a reference to '../../trpc/node_modules/@aws-sdk/client-s3/dist-types'. This is likely not portable. A type annotation is necessary.
src/trpc.ts(5,14): error TS2742: The inferred type of 'trpcClient' cannot be named without a reference to '../../trpc/node_modules/@aws-sdk/client-s3/dist-types'. This is likely not portable. A type annotation is necessary.

my trpc procedures indeed use s3 client and the problem may be the fact that DTS for trpc starts as follows (packages/trpc/dist/index.d.ts)

import * as zod from 'zod';
import * as better_auth from 'better-auth';
import * as express from 'express';
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3'; // ?
import * as type_fest from 'type-fest';
import * as prisma from 'prisma';
import * as _trpc_server from '@trpc/server';

declare const auth: {
    handler: (request: Request) => Promise<Response>;
    api: better_auth.InferAPI<{
        ok: {

// 100500 locs below...

asset: _trpc_server.TRPCBuiltRouter<{
        ctx: object;
        meta: object;
        errorShape: _trpc_server.TRPCDefaultErrorShape;
        transformer: false;
    }, _trpc_server.TRPCDecorateCreateRouterOptions<{
        upload: _trpc_server.TRPCMutationProcedure<{
            input: {
                projectId: string;
                fileName: string;
                data: string;
            };
            output: _aws_sdk_client_s3.PutObjectCommandOutput; // ?
            meta: object;
        }>;

imo, how would Studio package know what _aws_sdk_client_s3 is when unlike trpc package, it does not have @aws-sdk/client-s3 installed?

#

trpc package uses tsup with that config

import { defineConfig } from 'tsup'

export default defineConfig((options) => {
  return {
    entry: ['index.ts'],
    format: 'esm',
    dts: true,
    watch: options.watch,
  }
})
{
  "include": ["."],
  "exclude": ["node_modules", "dist"],
  "compilerOptions": {
    "outDir": "dist",
    "skipLibCheck": true,
    "strict": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
#

[Turborepo + tsup] Cannot build DTS because using AWS S3 Client

#

I tried installing @aws-sdk/client-s3 to studio package as a dev dep but it did not help

modern sedge
#

Cannot build DTS because using AWS S3 Client

modern sedge
#

the gpt 4o replied with

The error you're encountering is related to TypeScript's inability to infer the type of trpcRouter without referencing a specific path in the zod library. This issue often arises when TypeScript tries to generate declaration files (.d.ts) and encounters types that are not portable or require explicit type annotations.

without referencing a specific path in the zod library
what's the problem with referencing it?

#

it must mean TS knows how to infer types but fails to produce a DTS with exact types that other packages can use?

#

how does it make sense

modern sedge
#

You really do just need to do what the error says, and write an explicit type annotation on the node the error is marked on. You have an implicit, direct, type-level dependency on an indirect dependency's types, and we can't resolve that issue for you - it's up to you how you want to reach in and get at the innards of your dependencies. Maybe you add whatever the type is coming from as a direct dependency, maybe you write your own equivalent type, maybe there's a winding road through aliases and reexports and conditional infers to get at the type that we can't automatically discern, but you can write as the annotation - whatever works for you.
https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2065572017

somber snow
#

Yeah, I think this is mostly an issue when libraries don't export all of their types.

modern sedge
#

so far i have read a plenty of threads on this issue whether it was trpc or turborepo or TS repo but all of these solutions were either not mentioning they were using my setup (turborepo, pnpm) not sharing their tsconfig or dts files, so the real solution and the root of the problem is unclear

#

i cannot compare anybody elses solution against by repo as I can't be sure they used to have same symptoms I am having now

#

like

C:/dev/web/jalyk/packages/studio/src/field.ts (33,17): The inferred type of 'useParsedFieldQuery' cannot be named without a reference to '../node_modules/@trpc/react-query/dist/getQueryKey.d-CruH3ncI.mjs'. This is likely not portable. A type annotation is necessary.

this one happens as i try to build a react component package, I will be crushed to manually provide an annotation to any of RQ inferred types 💀

#

to fix it i do as it says and directly mention all types it may need in the problematic field.ts module

import * as T from '../node_modules/@trpc/react-query/dist/getQueryKey.d-CruH3ncI.mjs'
type _ = typeof T

// useParsedFieldQuery somewhere here

and ts suddenly has no problem with it

#

but come on, i would hate to do it for every of erroring 10 modules and as my package grows with more modules... am i repeatedly going to put these arguably sane fixes in each one of them?