Closed daqingsu19 closed 3 years ago
I also have the same problem
Downgrade truffle to: 5.1.65
Set contracts and truffle-config.js solc version to: >=0.6.0 <0.8.0
Downgrade truffle to: 5.1.65 Set contracts and truffle-config.js solc version to:
>=0.6.0 <0.8.0
Yes downgrading to 5.1.65 works. Thanks a lot!
Downgrade truffle to: 5.1.65 Set contracts and truffle-config.js solc version to:
>=0.6.0 <0.8.0
Thank you sooooo much!😀
Thank you for this solution but why did you close the issue? it seems like if downgrading to a older version is the fix then it should still be open because it's still broken in 5.1.66 which is what new people will install by default
I'm having a similar issue. The initial build of my contracts works fine (when artifacts folder is empty). However, every subsequent time I try to truffle compile
, I get a weird error.
Compiling your contracts...
===========================
TypeError: Cannot read property 'imports' of undefined
at Object.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1)
at Generator.next (<anonymous>)
at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)
I'm attempting to build with solc
version 0.8.1
Same problem here
We had the same issue, commenting here to track progress.
Downgrade doesn't work
I'm having a similar issue. The initial build of my contracts works fine (when artifacts folder is empty). However, every subsequent time I try to
truffle compile
, I get a weird error.Compiling your contracts... =========================== TypeError: Cannot read property 'imports' of undefined at Object.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1) at Generator.next (<anonymous>) at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)
I'm attempting to build with
solc
version 0.8.1
have you found any solution to this?
I have been getting the same error and found 2 solutions. First is to use a older solidity version (it works for me with 0.6.6) or to use a different tool then truffle (like hardhat)
I have been getting the same error and found 2 solutions. First is to use a older solidity version (it works for me with 0.6.6) or to use a different tool then truffle (like hardhat)
I tried with Truffle v5.1.65 (core: 5.1.65) and Solc 0.6.6, but nothing works🤯
for me I had to delete truffle globally, delete node_modules in my project and then after reinstalling everything it worked
downgrading to 5.1.65 worked for me. curious to know why 5.1.66 didn't work
truffle compile --all
This works
truffle test
it just showed off this error:Compiling your contracts...
TypeError: Cannot read property 'imports' of undefined...
- I reinstalled Truffle:
npm install –g truffle@~5.1.65
- The OS of my device is Windows 10, and truffle, solidity and node.js versions are as follows: Truffle v5.1.65 (core: 5.1.65) Solidity v0.5.16 (solc-js) Node v12.16.1
- Then I declared
pragma solidity ^0.5.16;
at the begining of every contract. I also modified thefruffle-config.js
file of the project into:module.exports = { // See <http://truffleframework.com/docs/advanced/configuration> // for more about customizing your Truffle configuration! networks: { development: { host: "127.0.0.1", port: 7545, network_id: "*" // Match any network id }, develop: { port: 8545 } }, compilers: { //I added this parameter. solc: { version: "0.5.16" } } };
- Then under the project root directory(
project_name/
): I tried the commandtruffle test
again, it worked for me.
Downgrading to truffle@5.1.65 worked for me. npm install truffle@5.1.65
@jha-prateek answer of using "truffle compile --all" worked for me.
It seems most are making changes or adding new contracts and forgetting to recompile
OK, it seems a lot of people are having this problem. Does anyone have a reproduction example we could check out? Otherwise I'll attemtp to reproduce this myself, but I'm hoping someone has an example I can use directly. Thank you!
I have a suspicion that PR #3802 might fix this problem. However, I really need a reproduction example to be able to check...
Try to delete your build folder, it worked for me.
@haltman-at
Reproduction:
git clone 'https://github.com/runtimeverification/firefly-demo'
cd firefly-demo
git checkout f6c72e0
npm install
npm install ganache-cli
In one terminal:
./node_modules/.bin/ganache-cli -p 8145
In another terminal:
./node_modules/.bin/truffle test
Results in this error:
Using network 'development'.
Compiling your contracts...
===========================
TypeError: Cannot read property 'imports' of undefined
at Object.<anonymous> (/home/dev/src/firefly-demo/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1)
at Generator.next (<anonymous>)
at fulfilled (/home/dev/src/firefly-demo/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)
Truffle v5.1.66 (core: 5.1.66)
Node v10.23.0
Downgrading to 5.1.65 and the error goes away and tests run successfully.
I'm on Node 10.23.0, if it matters.
@ehildenb Thanks! I'll check it out.
Hm, I can't seem to reproduce this at the moment. I'll have to try some more combinations later, I guess. That said, I have a suspicion that #3802 might fix this anyway...
@jha-prateek answer of using "truffle compile --all" worked for me.
It seems most are making changes or adding new contracts and forgetting to recompile
Yes, but it's strange because truffle compile
should work even without using --all
flag. Truffle docs says --all: Compile all contracts instead of only the contracts changed since last compile.
Hm, I can't seem to reproduce this at the moment. I'll have to try some more combinations later, I guess. That said, I have a suspicion that #3802 might fix this anyway...
Can you check, how truffle compile --all
is working and not truffle compile
. This might help you in finding the problem. 😀
Ah, good point. I'd been compiling from scratch. But, the example given by @ehildenb above also involves compiling from scratch. So that doesn't help. Does anyone have a more specific reproduction example I could try, including which contracts to compile in what order?
OK, could people retry this with 5.1.67 and see if there's still a problem? Thanks all!
@haltman-at
I confirm that upgrading to 5.1.67 solved it for me, using the example provided here.
SIDE NOTE: This example only compiles successfully, but I can not deploy this contract. Can't find the issue.
Providing output:
[Execute command]
3_deploy_contracts.js
=====================
[Execute command]
[Execute command] Error: Migration LAPTOP\solidity_project\migrations\3_deploy_contracts.js invalid or does not take any parameters
at Migration._load (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:49:1)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Migration.run (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:171:1)
at Object.runMigrations (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
at Object.runFrom (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
at Object.runAll (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
at Object.run (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
at runMigrations (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:262:1)
at Object.run (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:227:1)
at Command.run (USER\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:136:1)
[Execute command] Truffle v5.1.67 (core: 5.1.67)
Node v14.15.3
[Execute command] Finished running command
[Azure Blockchain] Deploy failed
SIDE NOTE: This example only compiles successfully, but I can not deploy this contract. Can't find the issue.
UPD: I did a stupid error by not saving edited file using Visual Studio Code, so it was trying to deploy an empty file probably. The example is working.
Oh gosh, @haltman-at , I think I'm running into this issue while running truffle test
. Interestingly, it fails on my Arch machine and works on OS X.
update: pulled latest develop and it's fixed in my case.
╰─$ truffle test
Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/ReentrancyAttack.sol
> Compiling ./contracts/ReentrancyGuard.sol
> Compiling ./contracts/ReentrancyMock.sol
> Compiling ./test/TestGuard.sol
> Artifacts written to /tmp/test--1004680-D92aN45Zb2bp
> Compiled successfully using:
- solc: 0.8.1+commit.df193b15.Emscripten.clang
TestGuard
1) "before all" hook: prepare suite for "testTargetIsInitialized"
0 passing (169ms)
1 failing
1) TestGuard
"before all" hook: prepare suite for "testTargetIsInitialized":
TypeError: Cannot read property 'imports' of undefined
at Object.<anonymous> (/home/amal/work/truffle/packages/compile-common/src/profiler/requiredSources.ts:128:45)
at Generator.next (<anonymous>)
at fulfilled (/home/amal/work/truffle/packages/compile-common/dist/src/profiler/requiredSources.js:5:58)
The debug trace shows getImports
behaving differently, with [__Truffle__NotFound.sol]
on failing Arch, and []
for OS X.
2021-02-21T02:20:04.842Z compile-common:profiler:resolveAllSources resolveAllSources called
2021-02-21T02:20:04.848Z compile-common:profiler:getImports filePath: /home/amal/dev/txlog/reentrant/contracts/Migrations.sol
2021-02-21T02:20:04.859Z compile-common:profiler:getImports imports: [ '__Truffle__NotFound.sol' ]
2021-02-21T02:20:48.526Z compile-common:profiler:resolveAllSources resolveAllSources called
2021-02-21T02:20:48.536Z compile-common:profiler:getImports filePath: /Users/cds/dev/txlog/reentrant/contracts/Migrations.sol
2021-02-21T02:20:48.558Z compile-common:profiler:getImports imports: []
OK, I'm going to close this for now then as it appears to be fixed in 5.1.67. If there's still a problem here we can reoepn this.
Hi @haltman-at , I still have the problem on version 5.1.67. I have created a repo with the code to reproduce it: https://github.com/elranu/truffle-compile-error
PS C:\Dev\repos\gsn-demo2> truffle compile
Compiling your contracts...
===========================
TypeError: Cannot read property 'imports' of undefined
at Object.<anonymous> (C:\Users\mvica\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\mvica\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.1.67 (core: 5.1.67)
Node v14.15.1
OK, thanks, I'll check it out!
OK, I still can't reproduce this. :-/ I had to fix up the example a bit to make it compile -- turning up the version to 0.6.9, fixing the BaseRelayRecipient
import in MetaCoin
, installing @openzeppelin/contracts
and marking MetaCoin
as abstract -- but once I did it compiled just fine. I'm not sure what's going on here.
@haltman-at do not fix it. Just clone
, yarn
, and truffle compile
. I know it does not compile. But instead of getting a compilation error, I got the message I sent you before.
@haltman-at do not fix it. Just
clone
,yarn
, andtruffle compile
. I know it does not compile. But instead of getting a compilation error, I got the message I sent you before.
When I did what you described I still can't compile it because of the import errors (openzeppelin) and solc version, and I am getting compilations errors, but not the one you have sent.
Could you, please, provide minimal reproducible setup to check?
@RedCuckoo I just test it again. And probably is something of my environment. The strange thing is with older versions works fine. My environment is windows 10, npm install truffle -g, Truffle v5.1.67 (core: 5.1.67). Node v14.15.1. Really I don´t know what else I can add. Sorry.
@elranu Ah, I see, I did not get that error when compiling it without fixing it; I got ordinary compilation errors. So, I was unable to reproduce it that way either. I can try seeing if the version of Node is relevant, I suppose. If it's a Windows-specific problem that will be harder to test.
OK, using Node 14.15.1 didn't change anything on my end, I'm afraid. @elranu, just to be sure, are you absolutely certain that you properly uninstalled Truffle 5.1.66 and installed 5.1.67? (As always, we recommend upgrading via
npm uninstall -g truffle
npm install -g truffle
to prevent any problems.) Or are you sure that you don't possibly have two different versions of Truffle installed, say one globally and one locally? I realize this may be a stupid question, but I want to be certain here...
Hi @haltman-at. Thank you very much for your response. You can check in the repo I sent you, which does not have package.json with a local version. So I don't think it may be that.
Before I was working with version Truffle v5.1.56 and I have upgraded to 5.1.67. That´s the only difference I see. As you quoted I have use installed and uninstalled. What I did not do, is npm clean cache and restart the computer. I´ll do it soon, sorry. I have a deadline. I´ll let you know.
Thank you very much for all the help. You are amazing guys!
Regards, Mariano Vicario
TypeError: Cannot read property 'imports' of undefined
at Object.
Hello, i have the same problem with a recent version of truffle .
Same error Truffle v5.2.2 Solidity 0.6.12 Node v14.15.1 Web3.js v1.2.9
Getting the same error when running truffle test
:
TypeError: Cannot read property 'imports' of undefined
at Object.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1)
at Generator.next (<anonymous>)
at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)
Truffle v5.2.3 (core: 5.2.3)
Node v15.4.0
This is on MacOS 11.2.2.
You can reproduce it by following the steps here up until you finish testAdoption.test.js and run truffle test
for the first time.
Edit: This was actually fixed by changing pragma solidity ^0.5.16;
to pragma solidity >=0.5.16;
in all the Solidity files and adding
solc: {
version: "^0.5.16"
}
}```
instead of
```compilers: { //I added this parameter.
solc: {
version: "0.5.16"
}
}
in the truffle-config.js file.
@photonized Hm, so it's not Windows-specific, then.
I don't think the change to the config file is relevant, nor the particular pragmas. I think the real reason that making that change caused the problem to go away is that, by updating every source file, you caused the profiler to attempt to compile everything; and we know the problem doesn't occur when compiling everything.
But, I'll see if I can reproduce the problem with your example. I've had no luck with any of the others, but maybe this time will be different...
@photonized Sorry, did you leave something out? It seems like you intended to include reproduction steps, but there aren't any there. Was your "here" supposed to be a link? Thank you!
Oops, @haltman-at . By here, I meant https://www.trufflesuite.com/tutorials/pet-shop
OK, I'll have to try that out later, thanks!
OK, unfortunately I was still unable to reproduce the problem in this fashion. Sorry.
FYI, I had the same problem, I fixed it by using sudo to uninstalled the old truffle version and to install the latest truffle version V5.2.3 as follows:
sudo npm uninstall -g truffle
sudo npm install truffle -g
truffle compile
Compiling your contracts...
===========================
.....
> Compiled successfully using:
- solc: 0.6.12+commit.27d51765.Emscripten.clang
truffle version
Truffle v5.2.3 (core: 5.2.3)
Solidity - 0.6.12 (solc-js)
Node v12.21.0
Web3.js v1.2.9
I wanted to try out Truffle/Ganache. So I followed
https://ethereum.org/en/developers/tutorials/create-and-deploy-a-defi-app/
-I am having version issues with Truffle. This is what "truffle version" shows: Truffle v5.1.66 (core: 5.1.66) Solidity - 0.7.4 (solc-js) Node v15.5.1 Web3.js v1.2.9 I specified solc 0.7.4 in truffle-config.js because the openzeppelin that I use asks for pragma between 0.6 and 0.8. I specified "pragma solidity >=0.4.22 <0.9.0;" in my contracts. But when I do "truffle compile", I got this:
Compiling your contracts... ✔ Fetching solc version list from solc-bin. Attempt #1 ✔ Downloading compiler. Attempt #1. TypeError: Cannot read property 'imports' of undefined at Object. (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1)
at Generator.next ()
at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)
Truffle v5.1.66 (core: 5.1.66)
Node v15.5.1
Seems like I am not able to make truffle, solidity, and openzeppelin all happy wrt versions.