首页 > 解决方案 > 我该如何解决这个错误?错误:找不到模块

问题描述

我有两页:

区块链.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;

测试.js:

const Blockchain = require('./blockchain') ;
const bitcoin = new Blockchain() ;

bitcoin.createNewBlock(23833,'asjakdja' , 'asdasdasdadasd') ;
console.log(bitcoin);

当我使用node 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

我该如何解决这个问题?

标签: javascriptmodule

解决方案


推荐阅读