4

I am following this course from Stephen Grider, learning Solidity. I cam unable to use compile.js to compile solidity. I am using node.js version 12.18.3. solc version 0.4.25 and npm version 6.14.16.

Compile.js code:

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'];

Course

Inbox.sol code:

pragma solidity ^0.4.25;

contract Inbox {
    string public message;

    function Inbox(string initialMessage) public {
        message = initialMessage;
    }

    function setMessage(string newMessage) public {
        message = newMessage;
    }
}

This is the full error:

RangeError: Maximum call stack size exceeded
    at Object.$db [as dynCall_viiiiii] (C:\Users\iluka\Desktop\Solidity\Inbox\no
de_modules\←[4msolc←[24m\soljson.js:12:120931)
    at invoke_viiiiii (C:\Users\iluka\Desktop\Solidity\Inbox\node_modules\←[4mso
lc←[24m\soljson.js:1:1118207)
    at Array.pva (C:\Users\iluka\Desktop\Solidity\Inbox\node_modules\←[4msolc←[2
4m\soljson.js:13:29030)
    at Object.M9a [as dynCall_vi] (C:\Users\iluka\Desktop\Solidity\Inbox\node_mo
dules\←[4msolc←[24m\soljson.js:12:99033)
    at invoke_vi (C:\Users\iluka\Desktop\Solidity\Inbox\node_modules\←[4msolc←[2
4m\soljson.js:1:1115011)
    at Array.xta (C:\Users\iluka\Desktop\Solidity\Inbox\node_modules\←[4msolc←[2
4m\soljson.js:10:704784)
    at Object.Dfb [as dynCall_iii] (C:\Users\iluka\Desktop\Solidity\Inbox\node_m
odules\←[4msolc←[24m\soljson.js:12:130740)
    at invoke_iii (C:\Users\iluka\Desktop\Solidity\Inbox\node_modules\←[4msolc←[
24m\soljson.js:1:1119442)
    at Array.vta (C:\Users\iluka\Desktop\Solidity\Inbox\node_modules\←[4msolc←[2
4m\soljson.js:10:703080)
    at Object.Yfb [as dynCall_iiiiii] (C:\Users\iluka\Desktop\Solidity\Inbox\nod
e_modules\←[4msolc←[24m\soljson.js:12:131900)

2
  • Does this answer your question? Unexpected token '[' when running Solidity test Commented Jun 1, 2021 at 7:56
  • I've seen this question here in few variations. It seems that the course uses a deprecated way of compiling the contract. See my answer in the duplicate for a list of changes you need to make in your node.js code in order to compile the contract. In short, you need to pass an object containing few other params (including the source code) - not just the source code text. Commented Jun 1, 2021 at 7:57

3 Answers 3

1

I had the same error. Try this, it worked for me.

npm uninstall solc

npm install --save [email protected]

Sign up to request clarification or add additional context in comments.

Comments

0

consider downgrading module versions in package.json file followed with npm install.The above code snippet is working fine with following dependencies

  "dependencies": {
    "ganache-cli": "^6.12.2",
    "mocha": "^8.4.0",
    "solc": "^0.4.26",
    "web3": "^1.0.0-beta.26"
  }

Comments

0

In my case, I was using

pragma solidity ^0.4.17;

and

constructor() public {...}

instead of function

Lottery() public{...}

If you are using 0.4.25 solc version then constructor() is supported. Otherwise we get error like "RangeError: Maximum call stack size exceeded" and "Cannot destructure property 'interface' of 'require(...)' as it is undefined".

I got these above error while running mocha test.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.