【问题标题】:Is there any difference between module.exports and module.export in solidity?module.exports 和 module.export 在solidity上有什么区别吗?
【发布时间】:2022-10-24 15:49:15
【问题描述】:

尝试在此代码上使用 truffle 迁移时遇到问题:

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

修复它的方法是从模块.exports模块.export并使用松露迁移——重置.所以有效的代码是

const Migrations = artifacts.require("Migrations");

module.export = function(deployer) {
  deployer.deploy(Migrations);
};

所以问题仍然存在,module.exports 和 module.export 有什么区别

【问题讨论】:

  • 这个问题应该有标签javascript(或nodejs),而不是solidity,因为module.export与NodeJs中模块的处理方式有关,而不是在Solidity中

标签: solidity truffle web3


【解决方案1】:

实际上这些代码行不是可靠的,它是 JavaScript,但是当你使用 export 实际上你只从文件中导出 1 项但是当你使用 export 实际上你只是 export 和 object 并且这个对象的一个​​键被分配给你功能。 所以不同的是当你想从另一个文件中导入你的方法时,比如下面的代码块。

const item = () => {}    
module.export = item
// where you want import it you have to user somthing like this
const item = require('path of your file')

而当您使用导出时,实际上是从文件中导出和反对。

const item = () => {}    
module.exports = item
// where you want import it you have to user something like this
const { item } = require('path of your file') 

但在你的情况下,只使用出口,因为我有这方面的经验,它会做你的工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 2016-04-23
    相关资源
    最近更新 更多