I am new of using node.js and I get these error :
TypeError: Cannot set property 'size' of undefined at Object. (C:\Users\User\Documents\latihannode.js\javascript4\test\script 4.js:4:10) at Module._compile (internal/modules/cjs/loader.js:678:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10) at Module.load (internal/modules/cjs/loader.js:589:32) at tryModuleLoad (internal/modules/cjs/loader.js:528:12) at Function.Module._load (internal/modules/cjs/loader.js:520:3) at Function.Module.runMain (internal/modules/cjs/loader.js:719:10) at startup (internal/bootstrap/node.js:228:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
in the notification this is the error code:
die.size = 10;
this is the code in page script4.js:
var dice = require('./dice');
var die = dice.die;
die.size = 10;
console.log(die.roll());
console.log(die.roll());
console.log(die.roll());
console.log(die.totalRolls);
console.log(die);
and this is in page dice.js:
var die = {
size: 6,
totalRolls: 0,
roll: function() {
var result = Math.ceil(this.size * Math.random());
this.totalRolls += 1;
return result;
}
};
exports.game = die;
exports.name = "My dice exports";
diceis null or not? - lucumtdieis undefined, just as it says in the error message. Doesdicehave adieexport? - user9315861dice.die;is undefined. Look at your exports, do you see die? No. I see game and name. Basic debuggingvar dice = require('./dice'); console.log(dice);<-- look to see what dice outputs to your developer console. - epascarello