Cannot destructure property 'interface' of 'require(...)' as it is undefined

gugu

I'm receiving this console error: "Cannot destructure property 'interface' of 'require(...)' as it is undefined."

Can somebody spot the wrong?

Inbox.test.js file:

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 accounts;
let inbox;

beforeEach(async ()=>{
// get a list of all accounts.
accounts = await web3.eth.getAccounts();
    // use ne of them to deploy.
inbox = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data: bytecode, arguments: ['Hi there!'] })
.send({from: accounts[0], gas: '1000000'});
});

describe('Inbox', ()=>{
it('deploys a contract', ()=>{
    console.log(inbox);
});
});

inbox.sol file: pragma solidity ^0.4.17;

contract Inbox{
string public message;
function inbox(string initialMessage) public {
    message = initialMessage;
}
function setMessage(string newMessage) public {
    message = newMessage;
}
function doMath(int a, int b){
    a+b;
    b-a;
    b*a;
    a==0;
}
}

compile.js file:

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

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

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

I would suggest you verify your project structure. Your compile.js must be in a parent folder of Inbox.test.js.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Electron JS - Cannot destructure property 'BrowserWindow' of 'require(...).remote' as it is undefined

Cannot destructure property 'latitude' of 'undefined'

Cannot destructure property 'isActive' of 'undefined' as it is undefined

TypeError: Cannot destructure property 'position' of 'undefined' as it is undefined

Uncaught TypeError: Cannot destructure property 'dialog' of 'require(...).remote' as it is undefined even thought enable remote modules set to true

Get an error cannot destructure property as it is undefined

TypeError: Cannot destructure property `compile` of 'undefined' or 'null'

× TypeError: Cannot destructure property 'xxx' of 'Object(...)(...)' as it is undefined

Cannot destructure property of object from context as it is undefined

Jest/Enzyme | Cannot destructure property on null or undefined

Cannot destructure property `variableName` of 'undefined' or 'null'

Cannot destructure property `auth` of 'undefined' or 'null'

Cannot destructure property 'data' of '(intermediate value)' as it is undefined

Cannot destructure property `user` of 'undefined' or 'null'

TypeError: Cannot destructure property `body` of 'undefined' or 'null'

TypeError: Cannot destructure property 'cartItems' of 'cart' as it is undefined

TypeError: Cannot destructure property 'toDos' of 'Object(...)(...)' as it is undefined

TypeError: Cannot destructure property 'product' of 'productDetails' as it is undefined

TypeError: Cannot destructure property 'name' of 'item' as it is undefined

TypeError: Cannot destructure property 'error' of 'panelMembersList' as it is undefined

React js Cannot destructure property as it is undefined

TypeError: Cannot destructure property 'paymentInfo' of 'order' as it is undefined

Cannot destructure property 'history' of 'undefined' as it is undefined. --React.js

TypeError: Cannot destructure property 'userId' of 'req.body' as it is undefined

Uncaught TypeError: Cannot destructure property 'recipes' of 'props' as it is undefined

NPM giving error - TypeError: Cannot destructure property `stat` of 'undefined' or 'null'

TypeError: Cannot destructure property 'credentials' of 'this.props' as it is undefined

Uncaught TypeError: Cannot destructure property 'xxx' of 'useAuth(...)' as it is undefined

MERN - TypeError: Cannot destructure property 'username' of 'req.body' as it is undefined