【问题标题】:React throwing error code when trying to install d3 version [closed]尝试安装d3版本时反应抛出错误代码[关闭]
【发布时间】:2021-11-04 23:44:21
【问题描述】:

所以我有一个分叉项目,我试图在我的 React 代码中引用。我注意到该软件包的 d3 版本与我自己的不同(它使用 5.5.0,我的使用 6.6.2)。每当我尝试做npm install d3@5.5.0 我收到了这些错误

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/<username>/react-d3-graph.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

我创建了一个 .env 文件。我知道了

SKIP_PREFLIGHT_CHECK=true
REACT_APP_React=SHA256:/<code>

我已经删除了 node_modules 和 package-lock.json。 我确认代码与我在 GitHub 上的 SSH、标题和所有内容相同。我不太确定为什么会这样。

这是我的 package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "csvtojson": "^2.0.10",
    "d3": "^6.6.2",
    "d3-selection": "^2.0.0",
    "papaparse": "^5.3.0",
    "react": "^17.0.1",
    "react-data-table-component": "^7.0.0-alpha-5",
    "react-dom": "^17.0.1",
    "react-file-reader": "^1.1.4",
    "react-request": "^3.2.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.2",
    "react-scroll-wheel-handler": "^2.0.1",
    "styled-components": "^5.2.1",
    "use-neo4j": "^0.3.5",
    "web-vitals": "^1.0.1",
    "write-json-file": "^4.3.0",
    "xlsx": "^0.16.9",
    "xtypejs": "^0.7.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "api": "npx json-server --watch .\\src\\components\\limit.json --port 8000"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "axios": "^0.21.1",
    "d3-drag": "^2.0.0",
    "d3-force": "^2.1.1",
    "d3-zoom": "^2.0.0",
    "react-d3-graph": "<git_username>/react-d3-graph",
    "react-router-scroll": "^0.4.4",
    "react-use": "^17.2.4"
  }
}

【问题讨论】:

  • 你是问如何运行它还是如何将它包含在一个单独的项目中?
  • 我将如何实现它以便我仍然可以调用函数,以及我实现和导出的函数。因此,例如,如果我将函数更改为执行 a+b 而不是 b+c,它将调用我的函数执行 a+b。但是如何将它也包含在当前项目中
  • 该项目上的代码文件在export 他们的组件中看起来就像任何其他 JavaScript 应用程序一样。你能把你的分叉版本放在你项目的一个文件夹中,然后import你需要什么吗?或者您是否一定需要单独构建此项目并将其构建输出包含在您的项目中的node_modules 中?

标签: reactjs github d3.js


【解决方案1】:

您需要更新您的 package.json 以指向您的分叉 github 存储库,而不是 react-d3-graph 的版本号。替换:

  "react-d3-graph": "x.y.z"

  "react-d3-graph": "your_github_username/react-d3-graph"

然后运行npm install

从那时起,它将使用您的版本而不是原始版本。

PS:请注意npm's support for github dependencies 远非完美。我仍然偶尔会遇到一些问题。显然,您还需要在任何时候对 repo 进行更改时重新运行 npm install。但话虽如此,它确实有效。

【讨论】:

  • 这将迫使您每次想要进行更改并使用您的 fork 时推送到 GitHub。还有其他选择,例如使用 npm link 或只是将项目放在 node_modules 中。
  • 是的,当然。但是npm link 也不是那么流畅的体验。尤其是在与他人协作、部署期间以及发布包时。在这些情况下,它会增加很多复杂性和陷阱。
  • 所以我已将 package.json 中的信息更改为我的 fork,但每当我更改某些内容并执行 npm install 时,它都会显示“最新”
  • 另外,随着 github 的新更新添加访问密钥,这不会影响我的阅读能力吗?因为我只是在更改我的包后尝试重新安装“react-d3-graph”,它说npm ERR! git@github.com: Permission denied (publickey). npm ERR! fatal: Could not read from remote repository. npm ERR! npm ERR! Please make sure you have the correct access rights npm ERR! and the repository exists.
  • 这当然只适用于公共分叉,但对于那些,当然不需要权限。 npm 在内部使用 https 协议。我不认为你看到的公钥错误是我提出的。
猜你喜欢
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
  • 1970-01-01
  • 2020-08-20
  • 2016-07-12
  • 2017-08-05
相关资源
最近更新 更多