3

Trying to transfer a custom token from one account to the other using this guide.

For some reason I'm getting four errors on all the imports from the @solana/spl-token package.

I've tried deleting the node-modules folder and rerunning npm install like in this post, but that didn't work. Still the same error.

The curious part:

I tried uninstalling the package and I still got the same error! That doesn't make sense? How is the compiler thinking that the package is still installed? What is going on?

The reason why it freaks out is because the previous version of the package 0.1.8 doesn't have those imports, but latest version 0.2.0 does. I installed 0.2.0. I explicitly have ^0.2.0 in my package.json

I'm new to TS so any help (even suggestions on how to debug better) here would be appreciated :)


Update: (title changed to reflect progress)

I think it's a dependency issue... from package-lock.json I saw there's a lot of other packages that install @solana/spl-token as a dependency, here's an example:

"@raydium-io/raydium-sdk": {
      "version": "1.1.0-beta.0",
      "resolved": "https://registry.npmjs.org/@raydium-io/raydium-sdk/-/raydium-sdk-1.1.0-beta.0.tgz",
      "integrity": "sha512-yN5M9sZNHazdMiUof2pHCBHs8FoGrfi2AWbLKAtKgnpJAWoyG7aLMLjeaVBc2L/xPuGsttUPP46dtqODwquJlg==",
      "requires": {
        "@colors/colors": "^1.5.0",
        "@solana/buffer-layout": "^3.0.0",
        "@solana/spl-token": "^0.1.8",
        "big.js": "^6.1.1",
        "decimal.js-light": "^2.5.1",
        "fecha": "^4.2.1",
        "lodash": "^4.17.21",
        "toformat": "^2.0.0"
      },
      "dependencies": {
        "@solana/buffer-layout": {
          "version": "3.0.0",
          "resolved": "https://registry.npmjs.org/@solana/buffer-layout/-/buffer-layout-3.0.0.tgz",
          "integrity": "sha512-MVdgAKKL39tEs0l8je0hKaXLQFb7Rdfb0Xg2LjFZd8Lfdazkg6xiS98uAZrEKvaoF3i4M95ei9RydkGIDMeo3w==",
          "requires": {
            "buffer": "~6.0.3"
          }
        },
        "@solana/spl-token": {
          "version": "0.1.8",
          "resolved": "https://registry.npmjs.org/@solana/spl-token/-/spl-token-0.1.8.tgz",
          "integrity": "sha512-LZmYCKcPQDtJgecvWOgT/cnoIQPWjdH+QVyzPcFvyDUiT0DiRjZaam4aqNUyvchLFhzgunv3d9xOoyE34ofdoQ==",
          "requires": {
            "@babel/runtime": "^7.10.5",
            "@solana/web3.js": "^1.21.0",
            "bn.js": "^5.1.0",
            "buffer": "6.0.3",
            "buffer-layout": "^1.2.0",
            "dotenv": "10.0.0"
          }
        }
      }
    },

So somehow typescript imports the dependency? So dumb but this fixes it:

import { getOrCreateAssociatedTokenAccount, transfer } from "../node_modules/@solana/spl-token"

It's not an answer, which is why i'm keeping this question up, I don't know why TypeScript would load the subfolder and not the main one.

JoeVictor
  • 1,806
  • 1
  • 17
  • 38

3 Answers3

1

Looks like you have another dependency making your @solana/spl-token library at version 0.18.0.

To fix this, manually import the newest version with

npm i @solana/spl-token@0.2.0

or

yarn add @solana/spl-token@0.2.0

Also, remove the ^ to enforce exact version in your package.json.

Jacob Creech
  • 1,797
  • 2
  • 11
1

This happens when you have two version of @solana/spl-token that are conflicting in versions

For example i had this issue when i was using metaplex's npm package which used the spl token package which was version 0.1.8 underneath and i had also separately installed it which was version 0.2.0

Just delete either and have only one version of the package

Anoushk
  • 551
  • 7
  • 20
1

You can refer to this question to create two different versions of the @solana/spl-token library. For example, execute the following to create two different libraries.

npm install @solana/spl-token-0.1.8@npm:@solana/spl-token@0.1.8

npm install @solana/spl-token-0.2.0@npm:@solana/spl-token@0.2.0

and then import the module using :

import { getOrCreateAssociatedTokenAccount, transfer } from "@solana/spl-token-0.2.0"
Juntaro
  • 11
  • 1