I'm trying to run a script using Puppeteer framework. (I'm a relative newbie to software). Every time I try to run, I get the error below. I'm sure nothing is wrong with the code as it worked fine an a different machine earlier. This error is noted right as main.js makes the (only) function call.
SyntaxError: Invalid or unexpected token
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
var puppeteer = require('puppeteer');
var $ = require('cheerio');
const url = 'https://www.reddit.com/controversial/';
puppeteer
.launch()
.then(function(browser) {
return browser.newPage();
})
.then(function(page) {
return page.goto(url).then(function() {
return page.content();
});
})
.then(function(html) {
$('h2', html).each(function() {
console.log($(this).text());
console.log('\r\n');
});
})
.catch(function(err) {
//handle error
});
I've uninstalled, cleaned, reinstalled Node.js as per this link (How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X))