'Error: Cannot find module './candy-machine-cli.ts'

I'm following a YouTube video about NFT minting and when I enter this:

ts-node js/packages/cli/src/candy-machine-cli.ts upload ./assets --env devnet --keypair ~/.config/solana/devnet-test.json

I get the following error:

node:internal/modules/cjs/loader:936 throw err; ^

Error: Cannot find module './candy-machine-cli.ts' Require stack: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.resolve (node:internal/modules/cjs/helpers:108:19) at requireResolveNonCached (C:\Users\Victoria\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:321:16) at getProjectSearchDir (C:\Users\Victoria\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:291:40) at main (C:\Users\Victoria\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:193:27) at Object. (C:\Users\Victoria\AppData\Roaming\npm\node_modules\ts-node\dist\bin.js:351:5) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) { code: 'MODULE_NOT_FOUND', requireStack: [ 'C:\Users\Victoria \Desktop\vicc\metaplex\js\packages\cli\src\imaginaryUncacheableRequireResolveScript' ] }

Then I tried

ts-node js/packages/cli/src/candy-machine-v1-cli.ts upload ./assets --env devnet --keypair ~/.config/solana/devnet-test.json

And this shows

[ERR] error: unknown command 'upload'

I really have no idea on how to fix this, would appreciate all the help.



Solution 1:[1]

I encountered the same issue as well. The trick here is to implement and get candy-machine working by using candy-machine-v2-cli.ts.

Candy Machine v1 is deprecated and it is v2 that you should use to create your candy machine.

The steps remain the same and you could try running the below command (which can be found with explanation here):-

ts-node ~/metaplex/js/packages/cli/src/candy-machine-v2-cli.ts upload \
    -e devnet \
    -k ~/.config/solana/devnet.json \
    -cp config.json \
    -c example \
    ./assets

Besides all this, I would recommend you read the docs on Candy Machine v2. It has covered things comprehensively.

Solution 2:[2]

first, create a config.json file in your root folder. follow https://docs.metaplex.com/candy-machine-v2/configuration

then run the command below in your terminal---

ts-node js/packages/cli/src/candy-machine-v2-cli.ts upload -e devnet --keypair -cp config.json -c example ./assets

get your keypair-path by using-- solana config get

this is work for me...

Solution 3:[3]

That error happens because you installed candy machine in a different location than this: js/packages/cli/src/candy-machine-v1-cli.ts. I had the same issue. I cloned the project into ~/metaplex directory in Linux.

git clone https://github.com/metaplex-foundation/metaplex.git ~/metaplex

then inside ~/metaplex run this command to install metaplex:

yarn install --cwd js

check the version. candy-machine-v2-cli.ts is in ~/metaplex

ts-node ~/metaplex/js/packages/cli/src/candy-machine-v2-cli.ts --version

So when I run command to upload, I put the location of candy-machine-v2-cli.ts

ts-node ~/metaplex/js/packages/cli/src/candy-machine-v2-cli.ts upload -e devnet -k ~./config/solana/devnet.json -cp config.json ./assets 

Note

Since you are on Windows, ~/ this might not work. So write the correct path

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P
Solution 2
Solution 3 Yilmaz