为什么我无法运行nodecompile.js?

问题描述 投票:0回答:2

我为我正在编写的智能合约编写了一个compile.js 文件(用于教育目的),但是当我使用

node compile.js
命令运行它时,我收到一条错误,提示
ReferenceError: compile is not defined

我在 Sublime Text 3 (windows 10) 中使用 Solidity ^0.4.17

它看起来像这样:

C:\Users\zakja\Desktop\inbox>node compile.js
C:\Users\zakja\Desktop\inbox\compile.js:1
compile.js
^

ReferenceError: compile is not defined
    at Object.<anonymous> (C:\Users\zakja\Desktop\inbox\compile.js:1:1)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m

下面是compile.js文件:

compile.js
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');


console.log(solc.compile(source, 1));


Any help is appreciated. (Note: Newbie here)
javascript node.js compiler-errors solidity smartcontracts
2个回答
0
投票

第一行是您的文件“compile.js”的名称。如果是,则删除第一行。您不需要文件名作为文件中的内容。删除第一行并运行。


0
投票

我现在也有同样的问题。你能解决吗?帮助将不胜感激,谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.