I need to require two js objects (Player & Room) into each other files. But when I did, an unexpected error occurred.
app.js:
const Player = require("./Player").Player
let player = new Player()
Player.js:
const Room = require ("./Room").Room
let room = new Room()
const Player = function () {
let room = new Room()
}
exports.Player = Player
Room.js:
const Player = require("./Player").Player
let player = new Player()
const Room = function () {
}
exports.Room = Room
And the error:
/home/mosi/Github/test/Room.js:2
let player = new Player()
^
TypeError: Player is not a constructor
at Object.<anonymous> (/home/mosi/Github/test/Room.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/mosi/Github/test/Player.js:1:14)
at Module._compile (internal/modules/cjs/loader.js:778:30)