MagicMirror² v2.14.0 is available! For more information about this release, check out this topic.

ReferenceError: Module is not defined...

  • Module Developer

    can someone please tell me what this error means and possibly how to fix it???

    0_1526589216715_Screenshot (3).png

    Any help is MUCH APPRECIATED!!!

  • Project Sponsor Module Developer


    I will tell you that I cannot see well enough to read your posted picture. If you would kindly copy any code you want to post and paste it in a code block, making it easily read by everyone, you’ll stand a better chance at receiving help.

    Starting MagicMirror: v2.3.1
    Loading config ...
    Loading module helpers ...
    Initializing new module helper ...
    Module helper loaded: MMM-NPMW
    No helper found for module: compliments.
    Initializing new module helper ...
    Module helper loaded: MMM-BMW
    All module helpers loaded.
    Starting server on port 8080 ... 
    You're using a full whitelist configuration to allow for all IPs
    Server started ...
    Connecting socket for: MMM-NPMW
    Starting node_helper for: MMM-NPMW
    Connecting socket for: MMM-BMW
    Starting node_helper for: MMM-BMW
    Sockets connected & modules started ...
    Launching application.

  • Project Sponsor Module Developer

    @justjim1220 you have an issue here. you are trying to run node yourmodule.js. First of all in MM it is used in the browser, so no node environment. Second the Module variable is nothing that comes from node or javascript itself it is a global variable for the MM thet gets placed in the browser too.

    What are you trying to achieve? Unit testing the module isolated. Run it without the MM project (does it make sense)? Why you are not setting it in the modules folder in MM and configure it in the config file to test it?

  • Module Developer


    First of all, I am pretty much a newbie to this module creation… This is my first attempt.

    I am using Visual Studio Code, and I was under the impression I could run a debug on the module itself. Sorry, My bad.

    What I’m getting from your replies, I should be inputting the whole MM project into the VS code environment, then run debug???

    Furthermore, I was having major issues trying to get the module to run on MM, then realized I needed to create it into a repository and do the git clone and install with the repository. I didn’t do that, I was just trying to create it and add it to my modules directory using the MM template (first item listed in the 3rd party modules).

    So, now, after figuring out that part, I have created a repository, went through the channels to add it to my MM, and now I’m getting it to show up on the mirror, it just isn’t playing.

    0_1526696438760_Screenshot (6).png

    This is what it looks like now…

    And this is the npm results while MM is running…

    Starting MagicMirror: v2.3.0-dev
    Loading config ...
    Loading module helpers ...
    No helper found for module: alert.
    Initializing new module helper ...
    Module helper loaded: updatenotification
    Initializing new module helper ...
    Module helper loaded: newsfeed
    No helper found for module: clock.
    Initializing new module helper ...
    Module helper loaded: MMM-RandomYouTubePlayer
    Initializing new module helper ...
    Module helper loaded: MMM-NOAA
    Initializing new module helper ...
    Module helper loaded: MMM-CalendarExt
    All module helpers loaded.
    Starting server on port 8080 ...
    Server started ...
    Connecting socket for: updatenotification
    Connecting socket for: newsfeed
    Starting module: newsfeed
    Connecting socket for: MMM-RandomYouTubePlayer
    Starting module helper: MMM-RandomYouTubePlayer
    Connecting socket for: MMM-NOAA
    Starting module: MMM-NOAA
    Connecting socket for: MMM-CalendarExt
    Sockets connected & modules started ...
    Launching application.
    Create new news fetcher for url:,%20MO,%20United%20States/Bethany,%20Missouri?ned=us&hl=en&gl=US - Interval: 300000

    I really do appreciate everyone’s input and getting me back into the coding realm! 😁

  • Module Developer

    OK, so if anyone out ther feels like it, here is my .js code…

    Module.register("MMM-RandomYouTubePlayer", {
    	defaults: {
    		playlistId: "PLl_KM23gznEAZW-INW8ty4QNaHH8JCnNW",
    		listType: "playlist",
            height: 480,
            width: 720,
            autoplay: true,
            disablekb: true,
            enablejsapi: true,
            color: "red",
            fs: false,
            volume: 100,
            cc_load_policy: true,
            controls: false,
            showinfo: false, 
            rel: false, 
            modestbranding: true,
            loop: true,
        getDom: function() {
    		var wrapper = document.createElement("div");
    		var scriptContainer = document.createElement('script');
    		// var playlistId = (this.config.playlist_ID);	
        	function onYouTubeIframeAPIReady() {
    			player = new YT.Player('player', {
    		    height: '480',
    		    width: '720',
    		    events: {
    			'onReady': onPlayerReady,
    			'onStateChange': onPlayerStateChange,
    		var playlistArray;
    		var playListArrayLength;
    		var maxNumber;
    		var oldNumber = 0;
    		var NewNumber = 0;
        	function newRandomNumber() {
    			oldNumber = NewNumber;
    			NewNumber = Math.floor(Math.random() * maxNumber);
    			if (NewNumber == oldNumber) {
    			} else {
    			    return NewNumber;
        	function onPlayerReady(event) {
    			    listType: "playlist",
    			    list: this.config.playlistId,
    		var firstLoad = true;
        	function onPlayerStateChange(event) {
    			if ( == YT.PlayerState.ENDED) {
    			} else {
    			if (firstLoad && == YT.PlayerState.PLAYING) {
    			    firstLoad = false;
    				playlistArray = player.getPlaylist();
    				playListArrayLength = playlistArray.length;
    				maxNumber = playListArrayLength;
    				NewNumber = newRandomNumber();
    		var TempDiv = document.createElement('div');
    		TempDiv.setAttribute("id", "player");
    		var tag = document.createElement('script');
    		tag.src = "";
    		var firstScriptTag = document.getElementsByTagName('script')[0];
    		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    		var player;
            var done = false;
    		wrapper.innerHTML = "";
    		return wrapper;

    Any and all hints, pointers, or input are very welcome and encouraged!!!

  • Project Sponsor Module Developer

    @justjim1220 first you should remove your calendr link from the logs, everyone is able to download your private calendar.

    If I remember correctly that youtube has settings to allow/prevent embedding maybe you have to change something there, as the player is there but the video not playing. Maybe it’s also just some videos that are not embedable.

  • Module Developer


    Thanks for answering…

    My calendar link is there, but my password is not. It does say private, but it actually is public, so anyone can see it, nothing too personal ever gets put on there anyway. 😏

    I can get a YT player to work on the MM, I’m just trying to figure out how to shuffle the list so it doesn’t start from the first song every time i gets loaded. And, if it’s just the video it has problems with, it gives a different error and will go to the next video. So, I know its not that either.

Log in to reply