solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
2.1k stars 845 forks source link

Cascade Bumping of dependencies after release cause typing error while rebuilding #2533

Closed vallhallalm closed 5 months ago

vallhallalm commented 5 months ago

Overview

Hi, While trying to reinstall the packages of my typescript application using npm v10.5.0 (node v20.12.1) I came across an issue that led me not to be able to build (using ./node_modules/typescript/bin/tsc). solana-web3.js has had a really recent release and it seems like the update of solana-web3.js create a cascade of dependencies update that leads me to the following kind of error:

node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts:72:44 - error TS1139: Type parameter declaration expected.

72 export declare function getDataEnumEncoder<const TVariants extends Variants<Encoder<any>>>(variants: TVariants, config?: DataEnumCodecConfig<NumberEncoder>): Encoder<GetEncoderTypeFromVariants<TVariants>>;
                                              ~~~~~

node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts:72:60 - error TS1005: ',' expected.

72 export declare function getDataEnumEncoder<const TVariants extends Variants<Encoder<any>>>(variants: TVariants, config?: DataEnumCodecConfig<NumberEncoder>): Encoder<GetEncoderTypeFromVariants<TVariants>>;
                                                              ~~~~~~~

node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts:72:76 - error TS1005: ',' expected.

72 export declare function getDataEnumEncoder<const TVariants extends Variants<Encoder<any>>>(variants: TVariants, config?: DataEnumCodecConfig<NumberEncoder>): Encoder<GetEncoderTypeFromVariants<TVariants>>;

Steps to reproduce

In a typescript app that contains "@solana/web3.js" as a dependencies in the package.json and which was not already updated after the recent release: delete node_modules folder, delete package-lock.json file, run npm i, run ./node_modules/typescript/bin/tsc

You should obtain the same kind of error as shown before.

Description of bug

When running ./node_modules/typescript/bin/tsc after installing back my node_modules I got the errors provided earlier. I expect not to get these errors just by installing back my packages

Thanks in advance for your help

lolelu commented 5 months ago

Same bug here.

TiaLanzi commented 5 months ago

Same bug here

djloa commented 5 months ago

same bug here

lolelu commented 5 months ago

For now, adding an override in package.json seems to be enough to solve the issue.

"overrides": { "@solana/spl-token": "0.3.5" }

spl-token library got updated in the last realease and it brings some broken references in.

steveluscher commented 5 months ago

Help me understand a bit more about what's going on here:

Things I know:

lolelu commented 5 months ago

As far as i managed to understand, @solana/codecs-data-structures is a dependency of @solana/codecs, which is somehow a dependency of @solana/spl-token, but only in version 0.4.5. Also, it doesn't bring in a stable version of @solana-codecs, but an unstable/preview one: @solana/codecs-data-structures

lolelu commented 5 months ago

Additionally, the package got updated litterally 4 hours ago, so it might be fixed by now.

steveluscher commented 5 months ago

I tried typechecking with @solana/spl-token@0.4.6 and it works. I'm pretty sure this is just my mistake from yesterday, and you all were unlucky enough to install 0.4.4 or 0.4.5 in your apps. Sorry about that. Please upgrade to 0.4.6.

steveluscher commented 5 months ago

Also possible: The TypeScript feature (const type parameters) in the OP was introduced in TypeScript 5. If you're on 4 you should upgrade.

statikdev commented 5 months ago

I am running into this same issue (0.4.6 of spl-token)

project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,44): error TS1139: Type parameter declaration expected.
project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,60): error TS1005: ',' expected.
project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,76): error TS1005: ',' expected.
project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,90): error TS1109: Expression expected.
project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,100): error TS1005: ')' expected.
project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,120): error TS1109: Expression expected.
project:build: ../node_modules/.pnpm/@solana+codecs-data-structures@2.0.0-preview.2/node_modules/@solana/codecs-data-structures/dist/types/data-enum.d.ts(72,156): error TS1005: ';' expected.

As far as i managed to understand, @solana/codecs-data-structures is a dependency of @solana/codecs, which is somehow a dependency of @solana/spl-token, but only in version 0.4.5. Also, it doesn't bring in a stable version of @solana-codecs, but an unstable/preview one: @solana/codecs-data-structures

The dependency resolution for me was to:

https://www.npmjs.com/package/@solana/codecs-data-structures/v/2.0.0-preview.2

Also possible: The TypeScript feature (const type parameters) in the OP was introduced in TypeScript 5. If you're on 4 you should upgrade.

what options do we have if we cannot upgrade to typescript 5?

steveluscher commented 4 months ago

You could consider patch-package to codemod out the const keyword, but you should upgrade to TypeScript 5 if at all possible.

github-actions[bot] commented 4 months ago

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.