Npm error when incuding x-ray-scraper in project

I’m developing an application in Vue, also using the x-ray-scraper library, but when I try to run npm run serve in the console to view the application locally I get the following error:

This dependency was not found:

* _http_common in ./node_modules/http-outgoing/index.js

To install it, you can run: npm install --save _http_common

Then I tried to run the command npm install --save _http_common and again I get an error:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected]_http_common.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

Without the x-ray-scraper library, everything starts up fine, but if I include it in my project, errors appear. Perhaps the error is related to the version, but I don’t understand how to fix it. My package.json looks like:

{
  "name": "pc-components",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "axios": "^0.21.0",
    "cheerio": "^1.0.0-rc.3",
    "core-js": "^3.6.5",
    "dns": "^0.2.2",
    "phantom": "^6.3.0",
    "selenium-webdriver": "^4.0.0-alpha.8",
    "vue": "^2.6.11",
    "webpage": "^0.3.0",
    "x-ray-scraper": "^3.0.6"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "vue-template-compiler": "^2.6.11"
  }
}

Thanks for any help.

Answer

The issue has nothing to do with the import statement, nor are there any issue with the dependencies you have installed.

This is my test:

  • npm init into any directory you want
  • npm install x-ray-scraper

Then:

const x = require("x-ray-scraper");

x('google.com', 'title')
 .then((title) => {
  console.log(title); // Google
});
// logs Google

You need a simple backend, even a couple of lines long, in order to initiate the service and use the package.

You can use whatever you like in the front-end, Vue, React, etc.

You do not need any extra dependencies at all from what you already have.

Please read the docs to see use cases