trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.32k forks source link

Downloading compiler #2631

Closed codepandy closed 2 years ago

codepandy commented 4 years ago
truffle compile

then

Compiling your contracts...
===========================
⠹ Downloading compiler. Attempt #1
ilifewebdev commented 4 years ago

me too ,same problem

CruzMolina commented 4 years ago

Hey @shch & @codepandy , can you provide full reproduction steps?

Which versions of Node, Truffle, & Solidity are you using while this error is happening? Does Truffle provide an error or does the process just hang?

ChaoChason commented 4 years ago

Hey @shch & @codepandy , can you provide full reproduction steps?

Which versions of Node, Truffle, & Solidity are you using while this error is happening? Does Truffle provide an error or does the process just hang?

me too ,same problem ,just hang,No report error .

Truffle v5.1.2 (core: 5.1.2)
Solidity v0.5.12 (solc-js)
Node v13.2.0
Web3.js v1.2.2
ChaoChason commented 4 years ago

Hey @shch @codepandy @CruzMolina

After a long wait, it can finally be executed. Guess what it's running in the background, and it's fast to execute now. It's so sad that there is no error.

leojames commented 4 years ago

me too . The same question

i-qcloud527:pet root# truffle compile

Compiling your contracts...

⠼ Fetching solc version list from solc-bin. Attempt #1

leojames commented 4 years ago

Hey @shch @codepandy @CruzMolina

After a long wait, it can finally be executed. Guess what it's running in the background, and it's fast to execute now. It's so sad that there is no error.

Do you slove it ? it need to download something or Bug ?

eggplantzzz commented 4 years ago

Hey everyone, is this still a problem for you? We'd like to know if we can do something about it if so, thanks y'all!

lychees commented 4 years ago

Seconded.

截屏2020-06-24 下午8 51 07
snowkidind commented 4 years ago

A POSSIBLE SOLUTION / HACK

NOTE: OSX 10.14.6

frustrating. it compiles using open zeppelin cli. installed locally, using npx truffle console

truffle(development)> version Truffle v5.1.32 (core: 5.1.32) Solidity - 0.6.2 (solc-js) Node v13.7.0 (also tried with v10.19.0 and v12.16.1) Web3.js v1.2.1

Compiling your contracts...
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #1.
✔ Downloading compiler. Attempt #2.
✔ Downloading compiler. Attempt #3.
Error: Could not find a compiler version matching 0.6.2. Please ensure you are specifying a valid version, constraint or build in the truffle config. Run `truffle compile --list` to see available versions.

On using npx truffle obtain 0.6.2

✔ Downloading compiler. Attempt #3.
Unbox failed!

Note I can (and have) try to download and build 0.6.2, or find a binary. But determining how to install these manually is ambiguous.

BUT....

sudo npx truffle compile appears to solve the problem.

Compiling your contracts...
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #3078 
> Compiling contracts/p.sol
> Artifacts written to /Users/keny/Desktop/ERC20/p/build/contracts
> Compiled successfully using:
   - solc: 0.6.2+commit.bacdbe57.Emscripten.clang

So I would say the solution has something to do with permissions when downloading the file but the error reporting is ambiguous as it does not say there was a permissions error.

 ls -al /Users/keny/.config/truffle/compilers/node_modules 
-rw-r--r--  1 root        staff  7985148 Jun 26 23:27 soljson-v0.6.2+commit.bacdbe57.js
ls -al /Users/keny/.config/truffle/compilers/
drwxr-xr-x  4 root        staff   128 Jun 26 23:27 node_modules

Now it appears to work. My thought is that truffle (this didnt work on a global install either) is unable to write a downloaded file into its compilers directory because apple is running some sort of gatekeeper and the program is not asking for permission to install thing downloaded from the interwebs.

Finally, after running sudo it appears to subsequently work, because it no longer needs to download the compiler into the directory.

lychees commented 4 years ago

@snowkidind It works.

haltman-at commented 4 years ago

Question for the people experiencing this issue. When you installed Truffle, did you use sudo or otherwise do it with root permissions? That may be the source of the problem. Thanks!

snowkidind commented 4 years ago

Local install, not global. sudo should not be required. But it's trying to install a compiler in a root - owned directory per my comment above.

eggplantzzz commented 4 years ago

I would say try using nvm or some other node version manager in this case. When you use nvm and npm it designates a different directory for installed packages which prevents permissions issues.

If anyone tries using nvm with npm to install and use Truffle can they let me know whether it resolves this problem?

snowkidind commented 4 years ago

Now that I understand the issue it's easy to resolve, but my notes point out that the error messages are pointing at the wrong error causing overall confusion. It looks like a failed download when it's a permissions error.

gnidan commented 4 years ago

Sounds like there's more we can do here to make the experience more clear. Calling this one "error better" and getting it onto our backlog. Thanks for the investigation everyone, and sorry for the inconvenience!

eggplantzzz commented 2 years ago

Is there something actionable here? Just evaluating whether we can close this.

gnidan commented 2 years ago

Seems like there's an action here to, upon error obtaining solc, detect the permissions of the compilers cache directory and, if the permissions are insufficient, suggest they rimraf the whole computer or something.

cc @cds-amal

inglkruiz commented 2 years ago

Hi, I just wanted to post what worked for me. For quick context, I'm deploying a Web IDE on K8s Environment which does not have access to internet. I built a container image with all the files I needed, pakcage.json, node_modules, etc.. For including the soljson-v... used by truffle I run when build the image

RUN npx truffle obtain --solc 0.8.3 && \
  npx truffle obtain --solc 0.8.9 && \
  npx truffle obtain --solc 0.8.11 && \
  npx truffle obtain --solc 0.8.14

That command created the following folder /root/.config/truffle/compilers/node_modules/ and /root/.config/truffle-nodejs/compilers/node_modules/ so I had to create the same folder for the user I set to run the container using the following:

RUN mkdir -p /home/coder/.config/truffle/compilers/node_modules && \
  mkdir -p /home/coder/.config/truffle-nodejs/compilers/node_modules && \
  cp -R /root/.config/truffle/compilers/node_modules/* /home/coder/.config/truffle/compilers/node_modules/ && \
  cp -R /root/.config/truffle-nodejs/compilers/node_modules/* /home/coder/.config/truffle-nodejs/compilers/node_modules/

RUN chown -R $UID:$UID /home/coder && \
  chmod -R 777 /home/coder

Altogether the last lines of my Dockerfile looks like this

RUN npx truffle obtain --solc 0.8.3 && \
  npx truffle obtain --solc 0.8.9 && \
  npx truffle obtain --solc 0.8.11 && \
  npx truffle obtain --solc 0.8.14

WORKDIR /home/coder/project

ENTRYPOINT ["dumb-init", "fixuid", "-q", "/usr/local/bin/code-server", "--host", "0.0.0.0", "--disable-updates", "--disable-telemetry", "/home/coder/project"]

USER root

RUN mkdir -p /home/coder/.config/truffle/compilers/node_modules && \
  mkdir -p /home/coder/.config/truffle-nodejs/compilers/node_modules && \
  cp -R /root/.config/truffle/compilers/node_modules/* /home/coder/.config/truffle/compilers/node_modules/ && \
  cp -R /root/.config/truffle-nodejs/compilers/node_modules/* /home/coder/.config/truffle-nodejs/compilers/node_modules/

RUN chown -R $UID:$UID /home/coder && \
  chmod -R 777 /home/coder

USER $UID

I hope this helps someone.

benjamincburns commented 2 years ago

Hi @inglkruiz,

Just a tip in case you aren't aware, the .config directory is being created under the /root directory during your docker build, because the docker build defaults to running as root within the temporary build containers that docker sets up when running docker build.

Assuming that coder is a known user inside of your docker image, you could likely switch to that user via the USER coder directive prior to running the npx truffle obtain ... commands.

If the coder user is not known to your environment, you could add it by doing RUN useradd -Dm coder, and then switch to it using the USER coder directive.

If that still doesn't fix the issue, try wrapping your command in a bash login console, like so:

USER coder
RUN /usr/bin/env bash -lc 'for VERSION in 0.8.3 0.8.9 0.8.11 0.8.14 do; npx truffle obtain --solc $VERSION; done'
revoltez commented 2 years ago

i changed the ownership of ~/.config/truffle-nodejs and it worked chown userName -R ~/.config/truffle-nodejs in my case the problem was that the file was locked to use only by root even though i never installed truffle using sudo

lsqproduction commented 2 years ago

Closing for issue maintenance.