Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Compile Error #3798

Closed
daqingsu19 opened this issue Feb 12, 2021 · 86 comments
Closed

Compile Error #3798

daqingsu19 opened this issue Feb 12, 2021 · 86 comments

Comments

@daqingsu19
Copy link

  • [x ] I've asked for help in the Truffle Gitter before filing this issue.

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.

@Eliseowzy
Copy link

I also have the same problem

@xternet
Copy link

xternet commented Feb 13, 2021

Downgrade truffle to: 5.1.65
Set contracts and truffle-config.js solc version to: >=0.6.0 <0.8.0

@daqingsu19
Copy link
Author

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!

@Eliseowzy
Copy link

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!😀

@zacel
Copy link

zacel commented Feb 13, 2021

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

@daqingsu19 daqingsu19 reopened this Feb 13, 2021
@khushjammu
Copy link

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

@fernandezpaco
Copy link

Same problem here

@ehildenb
Copy link

We had the same issue, commenting here to track progress.

@jha-prateek
Copy link

Downgrade doesn't work

image

@jha-prateek
Copy link

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?

@zacel
Copy link

zacel commented Feb 15, 2021

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)

@jha-prateek
Copy link

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🤯

@zacel
Copy link

zacel commented Feb 15, 2021

for me I had to delete truffle globally, delete node_modules in my project and then after reinstalling everything it worked

@sofianeOuafir
Copy link

downgrading to 5.1.65 worked for me. curious to know why 5.1.66 didn't work

@jha-prateek
Copy link

truffle compile --all

This works

@Eliseowzy
Copy link

  • Actually, I came to this trouble when I was testing my project, when I tried the command 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 the fruffle-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.

@ehildenb
Copy link

ehildenb commented Feb 16, 2021

Downgrading to truffle@5.1.65 worked for me. npm install truffle@5.1.65

@snwokenk
Copy link

@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

@haltman-at
Copy link
Contributor

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!

@haltman-at
Copy link
Contributor

I have a suspicion that PR #3802 might fix this problem. However, I really need a reproduction example to be able to check...

@sshmaxime
Copy link

Try to delete your build folder, it worked for me.

@ehildenb
Copy link

ehildenb commented Feb 17, 2021

@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.

@haltman-at
Copy link
Contributor

@ehildenb Thanks! I'll check it out.

@haltman-at
Copy link
Contributor

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
Copy link

@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.

@jha-prateek
Copy link

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. 😀

@haltman-at
Copy link
Contributor

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?

@soohanpark
Copy link

soohanpark commented Mar 31, 2021

Try to delete your build folder, it worked for me.

Cool, It's work for me :)
@ solc 0.8.0 + truffle 5.1.66

@lawrenceCP
Copy link

lawrenceCP commented Apr 4, 2021

@haltman-at @eggplantzzz

I am still hitting the same error after attempt with Truffle 5.1.66 and solc 0.8.0.

I tried downgrading truffle to 5.1.65 and using Node 10.23.0, it returns me the same error.

I tried with the latest truffle version seems like the issue still persists.

TypeError: Cannot read property 'imports' of undefined
at Object. (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next ()
at fulfilled (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.3.0 (core: 5.3.0)
Node v14.16.0

Let me know if I can be of any help.

@soohanpark
Copy link

@haltman-at @eggplantzzz

I am still hitting the same error after attempt with Truffle 5.1.66 and solc 0.8.0.

I tried downgrading truffle to 5.1.65 and using Node 10.23.0, it returns me the same error.

I tried with the latest truffle version seems like the issue still persists.

TypeError: Cannot read property 'imports' of undefined
at Object. (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next ()
at fulfilled (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.3.0 (core: 5.3.0)
Node v14.16.0

Let me know if I can be of any help.

have you try deleting build folder?

@lawrenceCP
Copy link

@haltman-at @eggplantzzz
I am still hitting the same error after attempt with Truffle 5.1.66 and solc 0.8.0.
I tried downgrading truffle to 5.1.65 and using Node 10.23.0, it returns me the same error.
I tried with the latest truffle version seems like the issue still persists.
TypeError: Cannot read property 'imports' of undefined
at Object. (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next ()
at fulfilled (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.3.0 (core: 5.3.0)
Node v14.16.0
Let me know if I can be of any help.

have you try deleting build folder?

Yup. I deleted and recompile the folder and test it each time I use a different version.. but hit into this error (with different version denote below) when i run truffle test... anyone hit the same issue as per mine?

@haltman-at
Copy link
Contributor

@lawrenceCP Are you still getting the error with Truffle 5.3.0? Could you confirm that? Thank you!

@Soohan-Park To be clear, deleting the build folder (or just using truffle compile --all, which I think would be easier) is a workaround; it's not something we want people to have to do! If the error is occurring, we want a clear reproducible example so that we can fix it, not for people to just resort to deleting their build folder!

@lawrenceCP
Copy link

@haltman-at yes, after tried delete the build folder (or run truffle compile --all) then run truffle test. I am still hitting the error with Truffle 5.3.0.

TypeError: Cannot read property 'imports' of undefined
at Object. (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next ()
at fulfilled (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.3.0 (core: 5.3.0)
Node v14.16.0

Which node version is the recommended version?

@haltman-at
Copy link
Contributor

@lawrenceCP OK, do you have some sort of reproduction example I could check out to figure out what's going on? Thanks! (I'll reopen the issue.)

We currently support Node 10, Node 12, and Node 14, although we may be dropping support for Node 10 in a few months.

@haltman-at haltman-at reopened this Apr 6, 2021
Current Batch automation moved this from Done to In progress Apr 6, 2021
@lawrenceCP
Copy link

@haltman-at lets try this:

  1. git clone https://github.com/lawrenceCP/testTruffle.git
  2. cd testTruffle
  3. truffle compile --all
  4. truffle test

Then you should be able to get an error similar to this.

TypeError: Cannot read property 'imports' of undefined
at Object. (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next ()
at fulfilled (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.3.0 (core: 5.3.0)
Node v14.16.0

@eggplantzzz
Copy link
Contributor

eggplantzzz commented Apr 8, 2021

To provide another data point here, @lawrenceCP I cloned your repo and had to fix a couple of imports. In TestAdoption.sol you had import "truffle/Deployment.sol where it should have been import/DeployedAddresses.sol. I also had to correct assert.equal to Assert.equal. After this truffle test ran without any errors. I ran it with Truffle 5.3.0 using both Node 10, 12, and 14.

Is it possible that you have other files in your repo that are not being committed or something? If you do a fresh clone and complete the steps you listed do you still get the error?

@lawrenceCP
Copy link

@eggplantzzz Thanks for the tips. After changing the import statement from import "truffle/Deployment.sol to import "truffle/DeployedAddresses.sol"

as well as the Assert.equal statement, I managed to run truffle test without errors.

@haltman-at may proceed to close off this issue. Thanks.

@haltman-at
Copy link
Contributor

@eggplantzzz I don't think that resolves this issue. Truffle shoud not produce errors, regardless of whether their imports are correct or not. If they have incorrect imports, they should see a compile error, not a Truffle error!

@joequant
Copy link

joequant commented Apr 9, 2021 via email

@eggplantzzz
Copy link
Contributor

eggplantzzz commented Apr 9, 2021

@haltman-at I didn't say it solves the original issue by the original poster. I am merely saying that after correcting the errors I listed, I am able to run truffle test without any errors: parser errors, compiler errors, or otherwise. When I first cloned the repo, there were a couple of issues with the contract that needed to be fixed (as I noted above).

@staringispolite
Copy link

I got this same error for a seemingly unrelated problem: I was missing a } in the newest contract I had just added

deleted /build
ran truffle compile --all
got me a slightly more helpful error: "FILENAME_HERE.sol:LAST_LINE_OF_FILE:1: ParserError: Function, variable, struct or modifier declaration expected."

realized/fixed the mistake
ran truffle compile --all
compiled successfully

@MatthewDHarrison
Copy link

I had this error too, got the undefined imports message only when running "truffle test" but not "truffle compile".
What worked for me:

  • deleting build folder
  • downgrading from v5.1.67 to v5.1.65
  • making sure import statements were correct (i.e. "truffle/Assert.sol" instead of "truffle/assert.sol")

The version of solidity didn't seem to matter, got it to work with 0.5.16 and >=0.8.0

@haltman-at
Copy link
Contributor

@lawrenceCP OK, I have successfully reproduced the error! Thanks so much for the example, sorry for taking so long to get back to this; I've had my hands pretty full. But now I can look into what's causing this and hopefully fix it.

@gideongrinberg
Copy link

This is still broken on the latest version and 0.5.15. Getting truffle to work with solc has just been painful.

@haltman-at
Copy link
Contributor

@gideongrinberg A fix for this (or what should be a fix for this) will go out with this week's release!

@gideongrinberg
Copy link

@gideongrinberg A fix for this (or what should be a fix for this) will go out with this week's release!

@haltman-at is there any temporary fix?

@haltman-at
Copy link
Contributor

Well, as other commenters have mentioned, the error doesn't occur when recompiling the whole project. But, if you can wait just a few hours a proper fix should go out in today's release, as mentioned, so any temporary workaround will be quite temporary indeed. :)

@haltman-at
Copy link
Contributor

The fix for this should be out now, so I'm closing this once again. If anyone sees this again, please let us know and we'll reopen it a third time.

Current Batch automation moved this from In progress to Done Apr 24, 2021
@sjschweber
Copy link

Hey, I am getting this error even with most recent version of truffle ...

Error: Truffle is currently using solc >=0.6.0 <0.8.0, but one or more of your contracts specify "pragma solidity ^0.8.0".

I tried multiple solutions provided in this thread (downgrading and changing solc version, and truffle compile --all), but none of them worked.

@sjschweber
Copy link

@haltman-at can you please re-open this issue

@haltman-at
Copy link
Contributor

@sjschweber You're describing an different issue; this issue is about an undefined reference crash, not about being unable to compile due to pragma mismatch. If you are having an issue with pragma mismatch, you might want to file a new issue for that, but I'd suggest that rather than file an issue for that you might want to start with talking to our support team to make sure this is an actual bug. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Current Batch
  
Done
Development

No branches or pull requests