在项目中包含 x-ray-scraper 时出现 Npm 错误

Npm error when incuding x-ray-scraper in project

我正在 Vue 中开发应用程序,也使用 x-ray-scraper 库,但是当我尝试在控制台中 运行 npm run serve 在本地查看应用程序时,我得到了以下错误:

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

然后我尝试 运行 命令 npm install --save _http_common 并且再次出现错误:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for undefined@_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.

没有 x-ray-scraper 库,一切都可以正常启动,但是如果我将它包含在我的项目中,就会出现错误。 也许错误与版本有关,但我不明白如何修复它。 我的 package.json 看起来像:

{
  "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"
  }
}

感谢您的帮助。

该问题与导入语句无关,也与您安装的依赖项无关。

这是我的测试:

  • npm init 进入任何你想要的目录
  • npm 安装 x-ray-scraper

然后:

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

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

您需要一个简单的后端,甚至几行,以便启动服务和使用包。

前端可以随便用,Vue,React等

您根本不需要任何额外的依赖项。

read the docs to see use cases