[英]I am getting this error: Block is not a constructor in node.js
I am new to Blockchain learning.我是区块链学习的新手。 I am following tutorial.我正在关注教程。 I am getting this error.我收到此错误。 I am unable to resolve in VS code.我无法在 VS 代码中解决。
const Block = require('./block');
describe('Block',()=> {
const timestamp='a-date';
const lastHash='foo-lasthash';
const hash='foo-hash';
const data=['foo-data','pdata'];
const block= new Block({
timestamp,
lastHash,
hash,
data
});
it('has a timestamp,lastHash,hash, and data property',()=>{
expect(block.timestamp).toEqual(timestamp);
expect(block.lastHash).toEqual(lastHash);
expect(block.hash).toEqual(hash);
expect(block.data).toEqual(data);
})
});
Here is the error message:这是错误消息:
FAIL /block.test.js
Block
x encountered a declaration exception ( 18ms )
• Block > encountered a declaration exception
TypeError : Block is not a constructor
91 const hash = ' foo - hash ' ;
10 | const data = [ ' foo - data ' , ' pdata ' ] ;
const block = new Block ( {
A
> 11
12 |
13 |
14 |
timestamp .
lastHash ,
hash ,
at Suite . < anonymous > ( block . test.js : 11 : 18 )
at Object . < anonymous > ( block.test.js : 6 : 1 )
Test Suites : 1 failed , 1 total
Tests : 1 failed , 1 total
Snapshots : 0 total
Time : 6.734s
Ran all test suites .
Looks like your require
statement is failing.看起来你的require
语句失败了。 You are initializing a block object const block= new Block
but Block
is not defined.您正在初始化一个块 object const block= new Block
Block
未定义块。
since usually class modules file names starts with capital letter it might be './Block'因为通常 class 模块文件名以大写字母开头,它可能是'./Block'
const Block = require('./Block')
or your relative path is wrong.或者你的相对路径是错误的。 './block' means your test and block
file are in the same directory. './block' 表示你的测试和block
文件在同一个目录中。 Make sure your relative path is correct确保您的相对路径正确
Also, I did not downvote (I dont downvote new users) but next time do not share image pls.另外,我没有投票(我不投票新用户),但下次不要分享图片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.