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

"Require is not defined" Error

Scheduled Pinned Locked Moved Solved Troubleshooting
3 Posts 2 Posters 572 Views 2 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.
  • W Offline
    WN
    last edited by Jul 30, 2021, 10:33 PM

    I have been trying create module can cant not get rid of this error

    Uncaught ReferenceError: require is not defined
    

    I have very little experience with node, so sorry if this has been asked a lot.

    getData: function(){
    		var self = this;
    		const dataRequest = require('https');
    		const options = {
    			"method": "POST",
    			"hostname": "",
    			"port": null,
    			"path": "",
    			"headers": {
    				"content-type": "application/json",
    				"clientsecret": "",
    				"clientid": "",
    				"x-rapidapi-key": "",
    				"x-rapidapi-host": "",
    				"useQueryString": true
    			}
    		};
    
    		const req = dataRequest.request(options, function (res) {
    			const chunks = [];
    			res.on("data", function (chunk) {
    				chunks.push(chunk);
    			});
    			res.on("end", function () {
    				const body = Buffer.concat(chunks);
    				console.log(body.toString());
    			});
    		});
    

    I would use something else but the API I am trying to use shows this as an example, and I am not the best with web calls. I don’t know if this is need but the API returns as json.

    S 2 Replies Last reply Jul 30, 2021, 11:16 PM Reply Quote 0
    • S Offline
      sdetweil @WN
      last edited by sdetweil Aug 3, 2021, 2:04 PM Jul 30, 2021, 11:16 PM

      @wn u cannot require in the web side. u might be able to load the script thru getScripts()

      otherwise u have to move that to the node_helper.js

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @WN
        last edited by Aug 3, 2021, 2:07 PM

        @wn also, you should not request/fetch IN getDom()… getDom() should ONLY format data already received…

        so you can start a routine with a timer, or some such, and when it produces data, save the data pointer somewhere, and then call updateDom() which informs MM that new content is available from your module…
        MM will then call getDom() to get the updated content to display

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          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