• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

ReferenceError: Module is not defined...

Scheduled Pinned Locked Moved Development
7 Posts 3 Posters 3.4k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    justjim1220 Module Developer
    last edited by May 17, 2018, 8:34 PM

    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!!!

    "Life's Too Short To Dance With Ugly People"
    Jim Hallock - 1995

    M S 2 Replies Last reply May 18, 2018, 1:08 AM Reply Quote 0
    • M Offline
      Mykle1 Project Sponsor Module Developer @justjim1220
      last edited by May 18, 2018, 1:08 AM

      @justjim1220

      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.
      

      Create a working config
      How to add modules

      1 Reply Last reply Reply Quote 0
      • S Offline
        strawberry 3.141 Project Sponsor Module Developer @justjim1220
        last edited by May 18, 2018, 5:00 AM

        @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?

        Please create a github issue if you need help, so I can keep track

        1 Reply Last reply Reply Quote 0
        • J Offline
          justjim1220 Module Developer
          last edited by justjim1220 May 19, 2018, 10:20 PM May 19, 2018, 2:25 AM

          @Mykle1
          @strawberry-3-141

          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: https://news.google.com/news/rss/local/section/geo/Bethany,%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! :grinning_face_with_smiling_eyes:

          "Life's Too Short To Dance With Ugly People"
          Jim Hallock - 1995

          1 Reply Last reply Reply Quote 0
          • J Offline
            justjim1220 Module Developer
            last edited by justjim1220 May 19, 2018, 2:42 AM May 19, 2018, 2:34 AM

            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) {
            			    newRandomNumber();
            			} else {
            			    return NewNumber;
            			}
               		}
            
                	function onPlayerReady(event) {
            			player.loadPlaylist({
            			    listType: "playlist",
            			    list: this.config.playlistId,
            			});
                	}
            
            		var firstLoad = true;
            
                	function onPlayerStateChange(event) {
                		console.log(event.data);
            			if (event.data == YT.PlayerState.ENDED) {
            			    player.playVideoAt(newRandomNumber());
            			} else {
            			if (firstLoad && event.data == YT.PlayerState.PLAYING) {
            			    firstLoad = false;
            
            				playlistArray = player.getPlaylist();
            				playListArrayLength = playlistArray.length;
            				maxNumber = playListArrayLength;
            				NewNumber = newRandomNumber();
            				player.playVideoAt(newRandomNumber());
            			}
            			}
            		}
            
            		wrapper.appendChild(scriptContainer);
            
            		var TempDiv = document.createElement('div');
            		wrapper.appendChild(TempDiv);
            		TempDiv.setAttribute("id", "player");
            
            		var tag = document.createElement('script');
            		wrapper.appendChild(tag);
            		tag.src = "https://www.youtube.com/iframe_api";
            
            		var firstScriptTag = document.getElementsByTagName('script')[0];
                    wrapper.appendChild(firstScriptTag);
            		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
            
            		var player;
                    var done = false;
            
            		wrapper.innerHTML = "<iframe width=\"" + this.config.width +"\" height=\"" + this.config.height + "\" src=\"https://www.youtube.com/embed/?" + this.config.listType + "&" + this.config.playlistId + "frameborder=\"0\"></iframe>";
            
            		return wrapper;
            	}
            });
            

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

            "Life's Too Short To Dance With Ugly People"
            Jim Hallock - 1995

            S 1 Reply Last reply May 19, 2018, 5:59 AM Reply Quote 0
            • S Offline
              strawberry 3.141 Project Sponsor Module Developer @justjim1220
              last edited by May 19, 2018, 5:59 AM

              @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.

              Please create a github issue if you need help, so I can keep track

              J 1 Reply Last reply May 19, 2018, 10:07 PM Reply Quote 1
              • J Offline
                justjim1220 Module Developer @strawberry 3.141
                last edited by May 19, 2018, 10:07 PM

                @strawberry-3-141

                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. :smirking_face:

                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.

                "Life's Too Short To Dance With Ugly People"
                Jim Hallock - 1995

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy