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

Cannot destructure property body of 'undefined' or 'null' (5.1.10 to any later version) #2834

Closed
slmatthiesen opened this issue Feb 17, 2020 · 33 comments · Fixed by #3075
Closed

Comments

@slmatthiesen
Copy link

slmatthiesen commented Feb 17, 2020

I've been using truffle with the same contract consistently for a while now (6 months easily). This latest upgrade 5.1.10 to 5.1.13 (I missed one) is the first time I've seen this error. Wondering if anyone else has.

Solution

Downgrading to 5.1.10 allows me to truffle migrate --network development without issue.


Issue

I've been using the same contract for 6+ months. After upgrading from 5.1.10 to 5.1.1x , I started getting this error when attempting to launch my contract on any network:

Cannot destructure property body of 'undefined' or 'null'

Downgrading to 5.1.10 allows me to launch my contract again. Worked my way down from 5.1.13 to 5.1.10.

Steps to Reproduce

truffle migrate --network development
or
truffle migrate --network ropsten

Expected Behavior

My contract would compile and launch as expected.

Actual Results

√ Fetching solc version list from solc-bin. Attempt #1
Error: TypeError: Error parsing C:/Users/Mine/Projects/project/contracts/Contract.sol: Cannot destructure property body of 'undefined' or 'null'.
at Object.compile (C:\Users\Mine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\legacy\index.js:80:1)

Environment

  • Operating System: Windows
  • Ethereum client:
  • Truffle version (truffle version): 5.1.13
  • node version (node --version): 12.15.0
  • npm version (npm --version): 6.13.7
@CruzMolina
Copy link
Contributor

Hey @slmatthiesen ! 👋

Can you share a reproduction repo for debugging purposes?

@ghost
Copy link

ghost commented Feb 19, 2020

I'm getting the error doing the pet-shop tutorial - executing 'truffle test':

  TestAdoption
    1) "before all" hook: prepare suite


  0 passing (438ms)
  1 failing

  1) TestAdoption
       "before all" hook: prepare suite:
     TypeError: Error parsing c:/Users/rm/Documents/Projects/pet-shop-tutorial/contracts/Adoption.sol: Cannot destructure property `body` of 'undefined' or 'null'.
      at getImports (C:\Users\rm\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\profiler\getImports.js:5:1)
      at C:\Users\rm\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\profiler\index.js:145:1

truffle version
Truffle v5.1.13 (core: 5.1.13)
Solidity v0.5.16 (solc-js)
Node v12.14.0
Web3.js v1.2.1

EDIT: downgraded to truffle v5.1.10 and working now!

@CruzMolina
Copy link
Contributor

CruzMolina commented Feb 19, 2020

Thanks for sharing that @README55 !

I notice both you and @slmatthiesen are on Windows 🤔.

@CruzMolina
Copy link
Contributor

Investigated a bit, this looks like a compilation OS-compatibility path issue.

@gnidan
Copy link
Contributor

gnidan commented Feb 19, 2020

Hooray a path compatibility issue! We'll have to dig into this. Thanks for raising this!

@CruzMolina
Copy link
Contributor

Actually, it might be a missing return in this PR (merged & released in v5.1.11) to get rid of some callbacks in the resolver code (specifically resolver/fs): https://github.com/trufflesuite/truffle/pull/2693/files#diff-741d320df0fc163eac3fec99a9e78b75R65

cc @eggplantzzz

@slmatthiesen
Copy link
Author

slmatthiesen commented Feb 20, 2020

Big ups to @README55 and thank you @CruzMolina
Thank you all and sorry for my delay in reply.

@eggplantzzz
Copy link
Contributor

Does anyone have reproduction steps for this error? It would be super helpful in diagnosing this. So far it looks like we only have a vague guess as to what is causing this.

@slmatthiesen
Copy link
Author

slmatthiesen commented Feb 20, 2020

Sure thing -

On a windows machine:

  1. Install truffle 5.1.13.
  2. Setup the petshop: https://www.trufflesuite.com/tutorials/pet-shop
    (Compact Sol files)
**[Adoption.sol]** 
pragma solidity ^0.5.0;
contract Adoption {
    address[16] public adopters;
    function adopt(uint petId) public returns (uint) {
    require(petId >= 0 && petId <= 15);
    adopters[petId] = msg.sender;
    return petId;
    }
    function getAdopters() public view returns (address[16] memory) {
    return adopters;
    }
}

**and

[TestAdoption.sol]**
pragma solidity ^0.5.0;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";
contract TestAdoption {
Adoption adoption = Adoption(DeployedAddresses.Adoption());
uint expectedPetId = 8;
address expectedAdopter = address(this);
    function testUserCanAdoptPet() public {
    uint returnedId = adoption.adopt(expectedPetId);
    Assert.equal(returnedId, expectedPetId, "Adoption of the expected pet should match what is returned.");
    }
    function testGetAdopterAddressByPetId() public {
    address adopter = adoption.adopters(expectedPetId);
    Assert.equal(adopter, expectedAdopter, "Owner of the expected pet should be this contract");
    }
    function testGetAdopterAddressByPetIdInArray() public {
    address[16] memory adopters = adoption.getAdopters();
    Assert.equal(adopters[expectedPetId], expectedAdopter, "Owner of the expected pet should be this contract");
    }
}
  1. Then run: truffle test
    or
    truffle migrate --reset --network development
    and you'll hit the
     TypeError: Error parsing C:/Users/___/Projects/pet-shop-tutorial/contracts/Adoption.sol: Cannot destructure property `body` of 'undefined' or 'null'.
      at getImports (C:\Users\me\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\profiler\getImports.js:5:1)
      at C:\Users\me\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\profiler\index.js:145:1

Downgrading to 5.1.10 on my personal contract does allow me to deploy it without issue.
Downgrading to 5.1.10 for the above removes the Cannot destructure property body of 'undefined' or 'null error but gives another (possibly because I threw the above together quickly and missed something)

@eggplantzzz
Copy link
Contributor

Thanks very much @slmatthiesen! I'll see if I can duplicate this on my mac.

@eggplantzzz
Copy link
Contributor

So I can confirm that your code example is able to run truffle test successfully on a mac. I had to add a migration to deploy the Adoption contract, but afterwards everything works fine. I'll have to see if I can test it on a Windows machine.

@yinjinit
Copy link

yinjinit commented Mar 4, 2020

Thanks @slmatthiesen and thanks you @CruzMolina . I had same issue using v5.1.15 and the old v5.1.10 solved my issue. Thanks again.

@24thsaint
Copy link

24thsaint commented Mar 13, 2020

@topnotchbiz downgrading solved my issue. Thank you!


Running on Windows with the following versions when this issue occurred:

Truffle v5.1.15 (core: 5.1.15)
Solidity - 0.5.16 (solc-js)
Node v13.5.0
Web3.js v1.2.1

@3rdstage
Copy link

I also met this problem right after upgrading to v5.1.18. I had tested this on my Windows 7 laptop with Node.js 10.15 and Ubuntu 16 guest of Virtual Boxy with Node.js 10.19, and found the same problem.
Deleting files under build directory ('build/contracts/*.json' files) doesn't help at all.

I downgraded my Truffle back to v5.1.9 and the problem disappeared. So, this problem is taught to appear after v5.1.10.

@ReedAlan
Copy link

Same happens to me on windows 10 (64bit)

C:\Users\Alan\Documents\DAPPS\pet-shop-tutorial>truffle version
Truffle v5.1.19 (core: 5.1.19)
Solidity v0.5.16 (solc-js)
Node v13.11.0
Web3.js v1.2.1

@4math2379
Copy link

i got the same issue with 5.1.19 / when i downgrade to 5.1.9 all compile perfectly.

I try to investigate the issue, but i really don't know where it come from.

@ajlopez
Copy link

ajlopez commented Apr 5, 2020

Today, I got this error, with truffle 5.1.14 in Windows 10

I removed build directory, and then truffle compile worked

@ReedAlan
Copy link

ReedAlan commented Apr 5, 2020 via email

@slmatthiesen
Copy link
Author

With the new release out (5.1.20) I thought I'd give it a try again.

  1. npm uninstall -g truffle
  2. npm install -g truffle
  3. Deleted my .json files in the build folder.
  4. truffle migrate --reset --network development

And the same project that didn't compile for me a month+ ago now compiled successfully!

Give it a try if you are having issues. If you need to revert just:
npm uninstall -g truffle
npm install -g truffle@5.1.10 (always got me back on track)

@pauliax
Copy link

pauliax commented Apr 8, 2020

Also experienced this issue with Truffle 5.1.20
Had to downgrade:
npm install truffle@5.1.9 -g

@MikeyDLuffy
Copy link

I experienced the same issue on Windows 10 (truffle@5.1.22) while using the MetaCoin box. The error was referring to the ConvertLib.sol library.

TypeError: Error parsing C:/Projects/MetaCoin/contracts/ConvertLib.sol: Cannot destructure property body of 'undefined' or 'null'.

Reverting to 5.1.10 solved the issue.

@xlwwww
Copy link

xlwwww commented Apr 21, 2020

yes,this problem can be solved by
npm install truffle@5.1.9 -g
and then delete the build directory and re-compile and migrate the contract

@gorgos
Copy link
Contributor

gorgos commented May 26, 2020

Can we fix this? I need something older than 5.1.16 due to #2723 🤦‍♂️

Update: Fixed in #3075. Thanks @CruzMolina for the direction.

@eggplantzzz
Copy link
Contributor

So does the problem still occur on version 5.1.33? It looks like some of the people in here had it resolve for them?

@slmatthiesen
Copy link
Author

Adding my 2c, I am able to compile a couple of my codebases successfully on Windows with: version 5.1.33

@spresnal
Copy link

spresnal commented Jul 9, 2020

Just updated my project to use 5.1.33 and this issue is still occurring for me

Edit:

  • Working version is 5.1.10 for me
  • Error occurs with MetaCoin project too

@eggplantzzz
Copy link
Contributor

So just to confirm @spresnal, you get this error after you unbox the metacoin project and run truffle test?

I'll have to go get a Windows machine to see if I can reproduce and troubleshoot this.

@EuLeEr
Copy link

EuLeEr commented Jul 13, 2020

I confirm . I get this error after you unbox the metacoin project and run truffle test.

Or https://www.trufflesuite.com/tutorials/pet-shop

PS C:\Users\Eugene\Documents\Ethereum\trufflequickstart\pet-shop-tutorial> truffle.exe test
Using network 'development'.


Compiling your contracts...
===========================
> Compiling .\contracts\Adoption.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\test\TestAdoption.sol
> Artifacts written to C:\Users\Eugene\AppData\Local\Temp\test-2020613-10852-1dkqhf.s5ohq
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

  TestAdoption
    1) "before all" hook: prepare suite for "testUserCanAdoptPet"

  0 passing (968ms)
  1 failing

  1) TestAdoption
       "before all" hook: prepare suite for "testUserCanAdoptPet":
     TypeError: Error parsing C:/Users/Eugene/Documents/Ethereum/trufflequickstart/pet-shop-tutorial/contracts/Adoption.sol: Cannot destructure property 'body' of 'undefined' as it is undefined.
      at getImports (C:\Users\Eugene\AppData\Local\Volta\tools\image\packages\truffle\5.1.34\build\webpack:\packages\compile-solidity\profiler\getImports.js:5:28)
      at C:\Users\Eugene\AppData\Local\Volta\tools\image\packages\truffle\5.1.34\build\webpack:\packages\compile-solidity\profiler\index.js:145:1

truffle version
Truffle v5.1.34 (core: 5.1.34)
Solidity v0.5.16 (solc-js)
Node v12.18.2
Web3.js v1.2.1
Windows 10 (10.0.19041.0)

@C0deMunk33
Copy link

yes,this problem can be solved by
npm install truffle@5.1.9 -g
and then delete the build directory and re-compile and migrate the contract

For anyone stumbling across this problem ^ is the quick fix

@avrdan
Copy link

avrdan commented Aug 9, 2020

@gnidan Why is this closed? How is downgrading the library considered to be a valid solution? I don't want to downgrade just to use one project. This should NOT be closed. Also, the problem occurs when running "test", not migrate.

I have the issue on Truffle v5.1.13.

@gorgos
Copy link
Contributor

gorgos commented Aug 9, 2020

@avrdan
Copy link

avrdan commented Aug 9, 2020

@gorgos Ok, great, thanks for the clarification. I think I had to switch to NodeLTS for another issue, however. #2070

@gorgos
Copy link
Contributor

gorgos commented Aug 9, 2020

@avrdan You can manually add those changes locally as a temporary fix: #3075. That's how I did it until 5.1.35 was released.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.