Google lens serpapi is giving me an abortsignal error. The code was the same the other day and now this error popped up? - javascript

My nodejs script was working perfectly fine the other day and now I'm getting this abort signal error below. The code is literally copied verbatim from the serpapi site. I had my own code that's slightly different but I get the same error even when just using the site's sample code. https://serpapi.com/google-lens-api. It seems to be a local issue because when I ran it standalone on Replit it seemed to be fine. My package json is below as well.
import { getJson } from "serpapi";
const params = {
url: "https://i.imgur.com/HBrB8p0.png",
api_key: "{xxx}"
};
// Show result as JSON
const response = await getJson("google_lens", params);
console.log(response["visual_matches"]);
"name": "cheerio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#google-cloud/vision": "^3.1.1",
"axios": "^1.3.2",
"cheerio": "^1.0.0-rc.12",
"jimp": "^0.22.4",
"node-fetch": "^3.3.0",
"openai": "^3.1.0",
"serpapi": "^1.1.0"
signal: AbortSignal.timeout(timeout),
^
ReferenceError: AbortSignal is not defined

Related

Failed launching test session: Error: Couldn't initialise "#wdio/cucumber-framework"

I am setting up the wdio using command "npm init wdio" and try to run the test files. it is giving below error
Failed launching test session: Error: Couldn't initialise "#wdio/cucumber-framework". [0-0] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/formatter/helpers/event_data_collector' is not defined by
Below is my package.json file
"name": "wdio-new",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wdio": "wdio run wdio.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#wdio/cli": "^7.16.12",
"#wdio/cucumber-framework": "^7.16.12",
"#wdio/local-runner": "^7.16.12",
"#wdio/spec-reporter": "^7.16.11",
"chromedriver": "^96.0.0",
"wdio-chromedriver-service": "^7.2.2"
}
}
I managed to fix this issue by reinstalling node and checking the option to "Automatically install the necessary tools" during setup

Cannot import Axios to use with Parcel-Bundler

I am trying to use axios for a http request in my app.js file, but I always get the error message:
Uncaught SyntaxError: Cannot use import statement outside a module.
I created the js folder, files and other js packages using parcel-bundler and run browser-sync to start the server.
What am I missing? Please help I am new to JavaScript. I am on macOS Big Sur 11.5.1, node v14.17.4
import axios from 'axios'
document.addEventListener('DOMContentLoaded', () => {
const form = document.querySelector('form')
form.addEventListener('submit', async (event) => {
event.preventDefault()
const username = document.querySelector('input').value
const response =
await axios.get(`https://api.github.com/users${username}`)
console.log(response.data)
})
})
In the closest (from the root of project directory) package.json file, add or update "type" field with a value of "module". It will ensure that all your .js, .ts and .mjs files are interpreted as ES modules.
...
{
...
"type": "module"
...
}
...
Where can I add it in this file?
{
"name": "githubUser",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1"
}
}
Add "type": "module" to your package.json
{
// ...
"type": "module",
// ...
}
Update:
It should looks like this:
{
"name": "githubUser",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1"
}
}

Mongo is not defined - problem while loading data from the server

I have a console bug. please help
Mongo is not defined - problem while loading data from the server
C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\utils.js:123
process.nextTick(function() { throw err; });
ReferenceError: mongo is not defined
at C:\Users\Robert\Desktop\FINISH\routes\info.js:38:70
at C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:122:13
at _each (C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:46:13)
at Object.async.each (C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:121:9)
at C:\Users\Robert\Desktop\FINISH\routes\info.js:34:31
at handleCallback (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\utils.js:120:56)
at C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\cursor.js:861:16
at handleCallback (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:171:5)
at setCursorDeadAndNotified (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:505:3)
at nextFunction (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:660:7)
package.json:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^0.9.0",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.10.2",
"bson": "^4.2.2",
"client-sessions": "^0.7.0",
"express": "^4.11.1",
"express-handlebars": "^2.0.1",
"mongodb": "^2.2.33"
}
}
Line 38 of info.js references mongo: mongo.ObjectID..., but mongo does not exist in that file. You need to add const mongo = require('mongodb') to the top of the file along with your require of the async module. And for future reference, you can edit posts on StackOverflow rather than replying with detail as an answer.

error: can not use import outside a module?

I never used a module outside a boilerplate created by for example create-react-app or angular-cli, now i am trying to mimic modularity without using them, and i get an error: cannot use import outside a module
this is my package.json file:
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0"
}
}
I am using a live-server to create a server for my project, I am failing to do that:
App.js:
const x = 10;
export default x;
index.js:
import x from './App' // can not use import outside a module
The question is what i missing here, what do i really need to create a module??

Javascript File load other Javascript files With no window/document

I'm working with javascript file that has no window or document.
I have package.json file that calls another Javascript file task.js
package.json:
{
"name": "mytask",
"version": "1.0.0",
"description": "mytask TFS Build",
"main": "scripts/mytask.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "npm install"
},
"repository": {},
"author": "OST",
"license": "ISC",
"dependencies": {
"https-proxy-agent": "1.0.0",
"jquery": "3.3.1",
"jsdom": "13.0.0",
"load-json-file": "^2.0.0",
"moment": "^2.22.2",
"object.values": "^1.0.4",
"request": "2.81.0",
"vso-node-api": "^5.1.2",
"vss-web-extension-sdk": "5.141.0",
"vsts-task-lib": "1.1.0"
}
}
TFS call javascript file exist in package.json "main" option.
package.json call mytask.js via "main" option and this javascript file will run as a task in TFS and print things to console.
Basically my issue that there's no HTML page or document so I cannot load javascript file through or document.addElement...
I need to load javascript file (VSS.SDK.js from vss-web-extension-sdk) to mytask.js.
I'm new in javascript so I don't really know what I'm doing wrong.
After long searching, I found "jsdom" which creates a global document. But still didn't know how to load VSS.SDK.js script.
mytask.js:
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM(`<!DOCTYPE html>`);
var jQuery = require("jquery")(window);
// Option 1
jQuery.loadScript = function (url, callback) {
jQuery.ajax({
url: url,
dataType: 'script',
success: callback,
fail: callback,
async: false
});
}
jQuery.loadScript('vss-web-extension-sdk/lib/VSS.SDK.js', function(){console.log("loaded!!!!!!!!!!!!!!!!!!!!")});
// Option 2
jQuery.getScript('vss-web-extension-sdk/lib/VSS.SDK.js').done(function(){console.log("loaded!!!!!!!!!!!!!")}).fail(function(){console.log("failed!!!!!!!!!!!!!!")});
// Option 3
jQuery.getScript('vss-web-extension-sdk/lib/VSS.SDK.js', function() {
VSS.init({explicitNotifyLoaded: true, usePlatformScripts: true, usePlatformStyles: false});
var serverContext = VSS.getWebContext();
});
I tried these three options but it didn't work! nothing was printed.
I use VSS.SDK to load webContext.
any ideas?

Categories