0

I've got his error in Solidity when compiling my test file: TypeError: Cannot destructure property interface of 'undefined' or 'null'.

I know it is related to my compile.js file, but what is unusual is that my tests compiled just fine until I tried to update the solidity compiler version. I then uninstalled the updated compiler version and restored the version it compiled with before but now have got this error.

This makes me think it is not related to a mistake in my compile.js file but to do with the solidity compiler. However, when I check the solc version (using solcjs --version), I have correct version that is compatible with my code.

My compile.js file is:

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const lotteryPath = path.resolve(__dirname, 'contracts', 'Lottery.sol');
const source = fs.readFileSync(lotteryPath, 'utf8');

module.exports = solc.compile(source, 1).contracts[':Lottery'];

my test file is:

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());

const {interface, bytecode } = require('../compile');

let lottery;
let accounts;

beforeEach(async () => {
    accounts = await web3.eth.getAccounts(); // unlocked accounts 
created automatically for us with ganache

    lottery = await new web3.eth.Contract(JSON.parse(interface))
    .deploy({data: bytecode})
    .send({from: accounts[0], gas: '1000000'}); 
});

describe('Lottery Contract', () => {

    it('deploys a contract', () => {
        assert.ok(lottery.options.address);
    });
});

Please help, this error has paralysed my work!

Some additional information, when I changed the solc compiler version, the pragma solidity ^0.5.0 declaration was underlined with a red squiggle indicating and error. When I hovered on the error it said the file requires a different compiler version (the old version that was used). How can the file be unable to recognised that the solc version has been updated? Could this be to do with the JSON files?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.