goetzrobin
goetzrobin10mo ago

TS4111: Property 'error' comes from an index signature, so it must be accessed with ['error'].

I am trying to use trpc with AnalogJs, an Angular meta framework and Nx. We use the @nx/vite builder to build our application. While development works perfectly, I am running into the following errors when building the application:
> nx run test:build:production

node_modules/@trpc/client/src/TRPCClientError.ts:42:18 - error TS4111: Property 'error' comes from an index signature, so it must be accessed with ['error'].

40 | return (
41 | isObject(obj) &&
> 42 | isObject(obj.error) &&
| ^
43 | typeof obj.error.code === 'number' &&
44 | typeof obj.error.message === 'string'
45 | );

...
> nx run test:build:production

node_modules/@trpc/client/src/TRPCClientError.ts:42:18 - error TS4111: Property 'error' comes from an index signature, so it must be accessed with ['error'].

40 | return (
41 | isObject(obj) &&
> 42 | isObject(obj.error) &&
| ^
43 | typeof obj.error.code === 'number' &&
44 | typeof obj.error.message === 'string'
45 | );

...
The issue stems from the @nx/vite builder analyzing the .ts files inside @trpc/client/src and @trpc/server/src folders of my node_modules. I was wondering why those src directories and the .ts files are included and if you are aware of any issues with React, Nx, and Vite? Thanks already!
3 Replies
Nick
Nick10mo ago
Sounds like a project config issue, check your tsconfig is excluding node_modules and see if skipLibCheck is the cause. I believe the latter shouldn’t be a problem as they recommend that stays on I think
goetzrobin
goetzrobin10mo ago
From what I understand skipLibCheck works by checking .d.ts files, not .ts files. I will check my config and see why the .ts files from the node_modules are considered. Can you help me understand why they are included? I am just curious what the reason for that is Also, thanks for responding so quickly! And awesome work with tRPC! I am very excited to continue to use it
Nick
Nick10mo ago
Not really sure what could be going on here, I'm not an expert in bundling and tooling Your node_modules should definitely not be having any .ts files checked, it smells like a tsconfig problem