Getting Errors on running truffle command: Cannot find module '#truffle/db-loader' - npm

I had several problems when downloading truffle -g. I had Error: EACCES: permission denied error. On my final attempt, I used sudo chown -R $USER /usr/local/lib/node_modules, and was able to download it successfully.
Issue
After downloaded Truffle, when I ran the command "truffle init" , I get an error that says command not found. Then I ran the command
"npx truffle init"
truffle inits successfully. But when I cd into my project folder and do "npx truffle init", I get an error
Error: Cannot find module '#truffle/db-loader'
Environment
Operating System: MacOS
Ethereum client:
Truffle version (truffle version): Truffle v5.5.25 (core: 5.5.25)
Ganache v7.4.0
node version (node --version): v16.15.1
npm version (npm --version): 8.11.0

Related

sh: hardhat: command not found when installing Hardhat

Trying to build a project with Hardhat, I have node v15.14.0, and ran the following commands:
npm init -y
npm install --save-dev hardhat
Terminal gives me:
Then I ran:
npx hardhat
But got an error saying:
sh: hardhat: command not found
You should use NPX.
The Node Package eXecute allows us to directly access and execute a package stored (or not) in $ ./node_modules/.bin/your-package.
Using npx hardhat [GLOBAL OPTIONS] <TASK> everything will works fine!
Running npm install --save-dev hardhat again did it for me.

Issues running truffle: command not found

I'm trying to deploy a Smart Contract, before that I need to run truffle compile but I get the error
bash: truffle: command not found
I've installed truffle with npm globally and locally, I tried these commands (worked for someone else in my course)
npm init
npm i truffle
./node_modules/.bin/truffle init
but when I run
npm i truffle
I get "unsupported architecture" amongst tons of other errors. all of these fixes are not working, how can I fix this problem from the root of it?
Also trying sudo:
sudo npm install -g truffle
does install it i guess but also gives the error:
truffle#5.4.14 postinstall /Users/khalidhamid/.npm-
global/lib/node_modules/truffle
> node ./scripts/postinstall.js
Error: EACCES: permission denied, open
'/Users/khalidhamid/Library/Preferences/truffle-
nodejs/config.json'
regardless, it still gives truffle: command not found
Is there any specific reason to install truffle using npm i truffle in your project? I mean, just install it globally and cd into your new directory and use truffle init to craft a new project. This way you can use truffle architecture to write your contracts and also use all available truffle commands. Also using truffle config file you can change the solidity compiler version according to your needs.

truffle installation issue "-bash : truffle: command not found"

i am trying to set up the environment for developing dapps on my mac using https://medium.com/tomochain/how-to-build-a-dapp-on-tomochain-85532a1192e7 tutorial. upon installing truffle, i am unable to use truffle commands from project directories. i think there is some issue with setting up the path variable or truffle not being a global installation.
Here is the output from the console
Sheikhs-MacBook-Air:~ Zubair$ node -v
v10.15.1
Sheikhs-MacBook-Air:~ Zubair$ npm -v
6.4.1
Sheikhs-MacBook-Air:~ Zubair$ truffle version
-bash: truffle: command not found
Sheikhs-MacBook-Air:~ Zubair$ ./node_modules/.bin/truffle version
Truffle v5.0.3 (core: 5.0.3)
Solidity v0.5.0 (solc-js)
Node v10.15.1
Sheikhs-MacBook-Air:~ Zubair$ cd pet-shop-tutorial
Sheikhs-MacBook-Air:pet-shop-tutorial Zubair$ truffle version
-bash: truffle: command not found
Sheikhs-MacBook-Air:pet-shop-tutorial Zubair$ ./node_modules/.bin/truffle version
-bash: ./node_modules/.bin/truffle: No such file or directory
Sheikhs-MacBook-Air:pet-shop-tutorial Zubair$ npm config get prefix
/Users/Zubair/pet-shop-tutorial/~.npm-global
Turns out it was an issue with the environment path variable.
needed to append "/Users/Zubair/~.npm-global/bin/" to the path variable to make truffle accessible from working directories.
This answer helped me resolve the issue.
https://ethereum.stackexchange.com/questions/52812/error-in-installing-truffle-in-macos

-bash: npm: command not found error message when installing React Native CLI on Mac

I'm following the latest instructions 05/31/2017 on installing React Native on https://facebook.github.io/react-native/docs/getting-started.html#content.
I'm attempting to install react-native. I successfully installed Homebrew, Node, Watchman but when I tried installing React Native CLI with this command:
npm install -g react-native-cli
it gave me this error message:
-bash: npm: command not found.
I then used this command:
curl -0 -L https://npmjs.org/install.sh | sudo sh
and the terminal gave me this message:
enter image description here
I then tried running this code:
react-native init AwesomeProject
but got this error message:
-bash: react-native: command not found
can someone help me overcome this obstacle so I can successfully installing React Native CLI? Thank you.
I already checked out the following but to no avail:
Error when installed react-native-cli command not found
Path error while installing react-native (Command not found error)
-bash: react-native: command not found
** NOTE **
node -v gives me v6.10.1
but when i do this:
npm -v it says -bash: npm: command not found
I thought npm came with node. Is it possible that I do not have npm but have can have nodejs?
Run npm install -g react-native-cli again. You didn't have npm installed before, when you ran the curl statement, that installed npm, but you now need to install the react-native-cli.

Truffle command not found after installation

I installed truffle through npm with the following:
sudo npm install -g truffle
but when I run truffle list on the console it just gives me
bash: truffle: command not found
I had a similar problem. I ran npm i -g truffle and then when I tried to run truffle init I got an error: zsh: command not found: truffle. What solved it for me is to create a local node_modules with truffle installed in it, and then run that copy.
run npm init and make a new npm project
run npm i truffle
run ./node_modules/.bin/truffle init and it should work!
Please make sure you have the latest version of npm and node installed. I had the same issue, I updated npm and node to latest version and it worked.
npm install -g truffle works.
After installing truffle:
npm install -g truffle
Run on your project folder:
npx truffle init
I did it on a Virtual box and had the same issue, but it worked after I restarted the computer. Hopefully that works for you too
You should add the following to your path system variable.
C:\Users\UserName\AppData\Roaming\npm
(This folder contains the truffle.cmd file)
I have tried and it works.
I tried everything. Followed the instruction on official truffle website and above answers.
Still it didn't seem to worked.
Finally, this worked for me.
Go to C:\Users\Username\AppData\Roaming\npm
There you will find truffle.cmd Double click on it and your done.
npm i truffle does the exact same thing as npm install -g truffle except that installs it globally, and without -g it will be installed on the local folder. Try to update the npm, node, and probably you have a broken node installation from previous versions.
Using npm install -g truffle worked for me instead of npm i truffle
Nothing above worked for me, but I did:
nix truffle unbox react
truffle develop
atom . //opens up the react file project in the atom platform
Try to start with your command like
npx truffle <your command>
You should add C:\Users\UserName\AppData\Roaming\npm (it contains truffle.cmd file) to the path user variables. I have tried and it works
If you have a custom path for your packages, then make sure that you are exporting it when the terminal loads.
For bash:
nano ~/.profile
For zsh:
nano ~./zshrc
And add your custom path, most of the time this will be "npm-global".
export PATH=~/.npm-global/bin:$PATH
These are two simple steps the properly solve this problem for Linux Users:
1- Configure npm to install software globally in your home directory as follows :
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
2- If you are using bash, then execute the following:
echo -n "export PATH=~/.npm-global/bin:$PATH" >> ~/.profile
However, if you are using zsh instead, then execute the following command:
echo -n "export PATH=~/.npm-global/bin:$PATH" >> ~/.zshrc
Note that, if you are using both bash and zsh, it is better to execute the two commands above.