Home > Software engineering >  Helper function is not defined error when using Reddit API?
Helper function is not defined error when using Reddit API?

Time:06-12

I'm getting a really weird error called "'scrapeSubreddit' is not defined no-undef" for this function I've created. I'm trying to use the Snoowrap API for Reddit results.

import Snoowrap from 'snoowrap';

function scrapeSubreddit(){
  const r = new Snoowrap({ 
    userAgent: 'myName',
    clientId: 'myID',
    clientSecret: 'mySecret',
  });

  const inspQuote = r.getSubreddit("quotes").getTop({time: 'week',limit:1});
  console.lop(inspQuote);
};


export default scrapeSubreddit;

Edit: I'm also additionally getting several Module not found errors, when I import this .js file into my main .js file for use. I get:

Module not found: Error: Can't resolve 'stream'

Module not found: Error: Can't resolve 'url'

Module not found: Error: Can't resolve 'querystring'

How do I solve this as well?

CodePudding user response:

I think that the problem is in import statement. You should import it like this :

const snoowrap = require('snoowrap');
  • Related