简体   繁体   中英

Helper function is not defined error when using Reddit API?

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?

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

const snoowrap = require('snoowrap');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM