"npm run build" ="react-scripts:权限被拒绝"; [英] "npm run build" = "react-scripts: Permission denied"

查看:505
本文介绍了"npm run build" ="react-scripts:权限被拒绝";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu 18.04上部署可正常运行的Windows 10 Spring-Boot/React应用程序,但是尽管进行了许多尝试修复,但仍不断收到"react-scripts:Permission denied"错误.希望你们中的一位反应专家可以发现我的错.

I'm trying to deploy my working Windows 10 Spring-Boot/React app on Ubuntu 18.04 but keep getting "react-scripts: Permission denied" error despite numerous attempts to fix. Hopefully one of you react experts can spot what I'm doing wrong.

我的package.json看起来像这样

My package.json looks like this

{
  "name": "medaverter-front",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.19.2",
    "bootstrap": "^4.4.1",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.0",
    "react-table-6": "^6.11.0",
    "react-validation": "^3.0.7",
    "reactstrap": "^6.5.0",
    "validator": "^12.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我以root用户身份登录,并使用nvm来安装node和lts.我这样安装了nvm:

I'm logged in as root and used nvm to install node and lts. I installed nvm like this:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

然后这样做:

nvm install node
nvm use node
nvm install --lts
nvm use --lts

然后我cd/var/lib/jenkins/workspace/MedAverter/medaverter-front并像这样安装node_modules:

Then I cd to /var/lib/jenkins/workspace/MedAverter/medaverter-front and install node_modules like this:

npm install -g

,然后将其递归更改为777,如下所示:

and then change the permissions to 777 recursively, like this:

chmod -R 777 node_modules

我还递归地将所有/root/.nvm权限更改为777,如下所示:

I also changed all the /root/.nvm permissions to 777 recursively, like this:

chmod -R 777 /root/.nvm

我可以使用一次构建它

npm run build

但是随后我从詹金斯那里运行了一个"Build Now",它以相同的方式失败了

but then I run a "Build Now" from Jenkins and it fails with the same

[[1;34mINFO[m] Running 'npm run build' in /var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] [[1;34mINFO[m] > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] > react-scripts build [[1;34mINFO[m] 
[[1;31mERROR[m] sh: 1: **react-scripts: Permission denied**
[[1;31mERROR[m] npm ERR! code ELIFECYCLE
[[1;31mERROR[m] npm ERR! errno 126
[[1;31mERROR[m] npm ERR! medaverter-front@0.1.0 build: `react-scripts build` 
[[1;31mERROR[m] npm ERR! Exit status 126

然后我cd/var/lib/jenkins/workspace/MedAverter/medaverter-front并运行

npm run build

并且再次出现相同的错误:

And also get the same error again:

> root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/lib/jenkins/workspace/MedAverter/medaverter-front#
> npm run build
> 
> > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front
> > react-scripts build
> 
> sh: 1: **react-scripts: Permission denied** npm ERR! code ELIFECYCLE
> npm ERR! errno 126 npm ERR! medaverter-front@0.1.0 build:
> `react-scripts build` npm ERR! Exit status 126

我花了数天时间试图解决这个问题.有建议吗?

I've literally spent days trying to figure this out. Suggestions?

推荐答案

我终于找到了解决此问题的方法.花了几天的时间.首先,我删除了Jenkins项目,并使用Pipeline而不是Freestyle创建了一个新项目.然后,我添加了带有脚本的Jenkinsfile.仍然失败,但是现在我可以灵活地添加其他命令来处理错误.

I finally figured out a solution to this problem. It took days of effort. First, I deleted the Jenkins project and created a new one using Pipeline, rather than Freestyle. Then I added a Jenkinsfile with a script. That continued to fail but now I had the flexibility to add in additional commands to handle the errors.

一个新的错误是关于玩笑的工人.我在DigitalOcean服务器上运行了以下命令以跳过该命令:

One new error was something about jest-worker. I ran the following command on the DigitalOcean server to get past that one:

yarn add jest-worker

然后我又遇到了旧的权限错误.我认为所有这些权限错误都是由于用户jenkins试图运行root用户拥有的内容而引起的,即使所有内容都具有777权限.我不明白,但是这就是我的解决方法.修改/etc/sudoers文件并添加以下行:

Then I had the old permissions error again. I think all these permission errors are due to user jenkins trying to run things owned by user root, even though everything had 777 permissions. I don't understand that but here's how I got around it. Modify the /etc/sudoers file and add the following line:

jenkins ALL=(ALL) NOPASSWD:ALL

然后修改Jenkins文件脚本以包括递归chmod和chown.这是最终工作的完整脚本:

Then modify the Jenkins file script to include recursive chmod and chown. Here is the full script that FINALLY worked:

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                echo 'Checkout...'
                sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front'
                checkout scm
                sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front'
                sh 'sudo chown -R jenkins /var/lib/jenkins/workspace/MedAverter/medaverter-front'
                stash 'sources'
            }
        }
        stage('Build') {
            steps {
                echo 'Build...'
                unstash 'sources'
                sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front'
                sh 'sudo chown -R jenkins /var/lib/jenkins/workspace/MedAverter/medaverter-front'
                sh 'mvn clean package -DskipTests'
                stash 'sources'
            }
        }
    }
}

我还不得不将DigitalOcean Droplet的内存从1GB增加到2GB,以克服另一个错误.如果有人知道更好的方法来克服令人沮丧的权限错误,请发表评论.

I also had to increase the memory of the DigitalOcean droplet from 1GB to 2GB to get past another error. If someone knows a better way to get past that frustrating permissions error, please comment.

这篇关于"npm run build" ="react-scripts:权限被拒绝";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆