Javascript 如何修复此错误?错误:找不到模块
我有两页: blockchain.js:Javascript 如何修复此错误?错误:找不到模块,javascript,module,Javascript,Module,我有两页: blockchain.js: function Blockchain() { this.chain = [] ; this.newTransactions = [] ; } Blockchain.prototype.createNewBlock = function (nonce,previousHash,hash) { const newBlock = { tranactions : this.newTransact
function Blockchain() {
this.chain = [] ;
this.newTransactions = [] ;
}
Blockchain.prototype.createNewBlock = function (nonce,previousHash,hash) {
const newBlock = {
tranactions : this.newTransactions,
nonce : nonce ,
hash : hash ,
previousHash : previousHash
};
this.newTransactions = [] ;
this.chain.push(newBlock);
return newBlock ;
}
module.exports = Blockchain;
const Blockchain = require('./blockchain') ;
const bitcoin = new Blockchain() ;
bitcoin.createNewBlock(23833,'asjakdja' , 'asdasdasdadasd') ;
console.log(bitcoin);
test.js:
function Blockchain() {
this.chain = [] ;
this.newTransactions = [] ;
}
Blockchain.prototype.createNewBlock = function (nonce,previousHash,hash) {
const newBlock = {
tranactions : this.newTransactions,
nonce : nonce ,
hash : hash ,
previousHash : previousHash
};
this.newTransactions = [] ;
this.chain.push(newBlock);
return newBlock ;
}
module.exports = Blockchain;
const Blockchain = require('./blockchain') ;
const bitcoin = new Blockchain() ;
bitcoin.createNewBlock(23833,'asjakdja' , 'asdasdasdadasd') ;
console.log(bitcoin);
当我使用节点test.js
时,它会产生以下错误:
Error: Cannot find module 'E:\wamp\www\blockchain\test'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:453:25)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:201:16)
at bootstrap_node.js:626:3
我如何解决这个问题?试试这个
const{Blockchain}=require('./Blockchain')代码>或这新区块链。区块链()
必须使用什么版本的js?我正在webstorme上工作IDE@Mark迈耶,对不起先生,我在dev文件夹里。。非常感谢。