I'm currently running a Mocha test of my Solidity contract but it throws error which is related to compiler code.
C:ethcompile.js:8
modules.exports = solc.compile(source).[];
SyntaxError: Unexpected token '['
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:ethestinbox.test.js:5:31)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.exports.requireOrImport (C:eth
ode_modulesmochalibesm-utils.js:42:12)
at Object.exports.loadFilesAsync (C:eth
ode_modulesmochalibesm-utils.js:55:34)
at Mocha.loadFilesAsync (C:eth
ode_modulesmochalibmocha.js:473:19)
at singleRun (C:eth
ode_modulesmochalibcli
un-helpers.js:125:15)
at exports.runMocha (C:eth
ode_modulesmochalibcli
un-helpers.js:190:10)
at Object.exports.handler (C:eth
ode_modulesmochalibcli
un.js:362:11)
at C:eth
ode_modulesmocha
ode_modulesyargsuildindex.cjs:443:71
The compiler itself is:
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');
modules.exports = solc.compile(source).[:Inbox];
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…