Trying to use a specific version of a node module (v0.2.0) in my own project, but one of my dependencies requires v0.1.8 of the same module. No issue, I thought, that dependency will use v0.1.8 in its nested node_modules
folder and my app will use v0.2.0 in my project’s node_modules
folder. I added v0.2.0 as a dependency to my package.json
and ran npm install
again. However, for some reason my app points to the other dependency’s v0.1.8 module (in its nested node_modules
) when I ctrl-click it, instead of the expected v0.2.0 module correctly installed in the project’s own node_modules
folder. Here’s the code I’m using to import from the modules (@metaplex/js relies on v0.1.8 of @solana/spl-token, while I need to use v0.2.0 of @solana/spl-token in my own app):
import { ... } from "@solana/spl-token"; import { ... } from '@metaplex/js';
I verified that the v0.1.8 spl-token was installed in ./node_modules/@metaplex/js/node_modules/@solana/spl-token
, and the v0.2.0 spl-token was installed in ./node_modules/@solana/spl-token
. I also ran npm ls @solana/spl-token
to make sure it was in the dependency tree, and here are the results:
├─┬ @metaplex-foundation/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f726f73326b70747a7132727a6b7e7b7e6b7e5f2e312d312a">[email protected]</a> │ └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="087b7864257c67636d66483826392630">[email protected]</a> ├─┬ @metaplex/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a30291a6e746b68746a">[email protected]</a> │ ├─┬ @metaplex-foundation/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbb6abb7f6baaeb8afb2b4b59bebf5ebf5e9">[email protected]</a> │ │ └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abd8dbc786dfc4c0cec5eb9b859a8593">[email protected]</a> │ ├─┬ @metaplex-foundation/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a475a4607474f5e4b5a464f526a1a041a041f">[email protected]</a> │ │ ├─┬ @metaplex-foundation/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfb2afb3f2abb0b4bab1f2b2baabbebbbeabbe9feff1eff1ed">[email protected]</a> │ │ │ └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5427243879203b3f313a14647a657a6c">[email protected]</a> deduped │ │ └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e99a9985c49d86828c87a9d9c7d8c7d1">[email protected]</a> │ ├─┬ @metaplex-foundation/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fe938e92d38a91959b90d3889f8b928abeced0ced0cc">[email protected]</a> │ │ └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a4a7bbfaa3b8bcb2b997e7f9e6f9ef">[email protected]</a> │ └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4878498d9809b9f919ab4c4dac5dacc">[email protected]</a> └── @solana/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdcecdd190c9d2d6d8d3fd8d938f938d">[email protected]</a>
I can’t figure out why my code still imports from the wrong version used by another dependency when I installed the correct version in my project’s node_modules
folder. Is there a workaround or solution to solve this?
fairly new to node, sorry
Edit: (my project is a typescript react project) did some more poking around and apparently, v0.1.8 of the module’s package.json
‘s types
property points to an *.d.ts
file like this:
declare module '@solana/spl-token' { export //functions, fields, etc }
while v0.2.0’s package.json
‘s types
property points to a simple *.d.ts
file like
export * from './instructions/index'; ...
(note there is no specific declare
keyword for the module itself)
and each function has a separate *.d.ts
where the specific member is declare
d, as such in functionName.d.ts
:
export declare function functionName(...): Promise<...>;
I don’t know if this change causes some type of namespace conflict but it seems like this is a very specific error having to do with this particular module and not something generally wrong with node.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
What do you mean by very specific error ?
This Is very common issue
At yow tsconfig.json set the baseUrl
AND paths
{ ... "baseUrl":"./node_modules", "paths":{ "name-of-the-package":[ "relative-to-baseurl/position/where/yow-code-is" ] }}
The position of yow code Is relative to baseUrl.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0