当我执行 npm install 时,Git Clone 的权限被拒绝

IT技术 json node.js reactjs github ubuntu-14.04
2021-04-11 01:22:16

我的 package.json 文件中有 git 依赖项。当我在 react 应用程序文件夹中执行sudo npm install时,出现此错误

    npm ERR! code 1
    npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master 
    https://github.com/lrojas94/react-file-base64.git /home/admin1/.npm/_cacache/tmp/git-clone-462782fb
    npm ERR! /home/admin1/.npm/_cacache/tmp/git-clone-462782fb/.git: Permission denied
    npm ERR! 

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/admin1/.npm/_logs/2017-07-18T08_58_10_906Z-debug.log
    admin1@ubuntu:~/hys_pms/ui$ nohup: appending output to ‘nohup.out’

这是我的 package.json

    {
      "name": "react-hys-app",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "annogenerate": "^0.8.1",
        "bootstrap": "^3.3.7",
        "cors-prefetch-middleware": "^1.0.0",
        "es6-promise": "^4.1.0",
        "express": "^4.15.3",
        "fixed-data-table": "^0.6.4",
        "flexbox-react": "^4.4.0",
        "font-awesome": "^4.7.0",
        "images-upload-middleware": "^1.1.1",
        "isomorphic-fetch": "^2.2.1",
        "jquery": "^3.2.1",
        "react": "^15.3.1",
        "react-autosuggest": "^9.0.1",
        "react-avatar-cropper": "^0.1.3",
        "react-bootstrap": "^0.30.8",
        "react-bootstrap-autosuggest": "^0.5.0",
        "react-bootstrap-date-picker": "^5.0.1",
        "react-bootstrap-table": "^3.3.1",
        "react-checkbox-list": "0.0.2",
        "react-datepicker": "^0.51.0",
        "react-datetime": "^2.8.10",
        "react-dom": "^15.4.0",
        "react-dual-listbox": "^1.1.0",
        "react-edit": "^6.3.0",
        "react-file-base64": "git+https://github.com/lrojas94/react-file-base64.git",
        "react-flexbox-grid": "^1.1.3",
        "react-grid-layout": "^0.14.6",
        "react-images-uploader": "^1.0.1",
        "react-pagify": "^2.2.0",
        "react-panelgroup": "^1.0.2",
        "react-radio-button-group": "^1.2.5",
        "react-redux": "^5.0.4",
        "react-router": "^2.7.0",
        "react-s-alert": "^1.3.0",
        "react-select": "^1.0.0-rc.5",
        "react-visibility-toggles": "^1.1.1",
        "reactabular-resizable": "^8.9.0",
        "reactabular-table": "^8.9.0",
        "recompose": "^0.23.5",
        "redux": "^3.6.0",
        "redux-devtools-extension": "^2.13.0",
        "redux-thunk": "^2.2.0",
        "redux-undo": "^1.0.0-beta9-9-1",
        "reflexbox": "^3.0.0-0",
        "schema2object": "^0.4.0",
        "searchtabular": "^1.5.0",
        "segmentize": "^0.4.1",
        "sortabular": "^1.4.0",
        "table-resolver": "^3.1.0"
      },
      "devDependencies": {
        "css-loader": "^0.28.4",
        "react-scripts": "0.9.5",
        "style-loader": "^0.18.2"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    }

package.json 中的这一行产生了问题。

"react-file-base64": "git+ https://github.com/lrojas94/react-file-base64.git "

我对这个问题感到震惊。请帮助。

4个回答

从 NodeJS 6.10 升级到 8.10(更重要的是,升级到 NPM 5.6.0)后,我在安装 chimp(不是从 git repo)时遇到了完全相同的错误。问题是 npm 5 处理权限/目录的方式与 npm 4 非常不同。

解决方案是在运行 npm 5 时永远不要使用 sudo。您会发现必须将它与 npm 4 一起使用的情况,但您不需要将 sudo 与 npm 5 一起使用。如果您要全局安装,请访问此链接可能会帮助你。它没有帮助我。

由于我在 docker 容器中,因此我可以修改我的 docker 文件以不使用 sudo,然后一切正常。如果你不是,我建议你以你的用户(不是 root)运行以下命令:

cd ~
sudo rm -rf .npm
cd <wherever your package.json/node_modules is>
npm cache clean
rm -rf node_modules
npm install

不知道你的问题解决了没有。今天我遇到了同样的问题,问题是 ~/.npm 文件夹被权限搞乱了,所以我改变了权限sudo chown -R $(whoami) ~/.npm,它工作正常。

这不是一个正确的修复(不要这样做),但它对我有用。进入超级用户模式,然后npm install使用sudo.

sudo su
sudo npm install
不要这样做,否则我会拒绝你的prs
2021-06-06 01:22:16
给你安装的module一个超级用户权限的坏习惯,你最终将不得不用相同的权限处理它们,这是一团糟。
2021-06-18 01:22:16

答案对我有用。建议使用find和/或sudo find删除任何 .npm 文件夹。