我正在尝试在Ubuntu 18.04上部署我的工作中的Windows 10 Spring-Boot/React应用程序,但无论如何都会收到"react-scripts: Permission denied"错误,尽管我尝试了许多方法来解决。希望你们中的某个React专家能够找到我哪里出了问题。
我的package.json文件看起来像这样:
{
"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的:
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
:
npm install -g
然后递归地将权限更改为777,像这样:
chmod -R 777 node_modules
我还递归地将所有/root/.nvm的权限更改为777,就像这样:
chmod -R 777 /root/.nvm
我可以使用以下命令构建
npm run build
但是我在Jenkins上运行“立即构建”时却遇到了相同的失败情况。[[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
同时再次出现相同的错误:
> 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
我已经花了好几天时间试图弄清楚这个问题。有什么建议吗?
node_modules
这个非全局目录的权限呢?你尝试过去掉-g
吗?另外,你的chmod操作是不必要的,而且实际上非常危险。请不要这样做。通常情况下,Permission denied意味着可执行标志未设置,或者它被分配给了另一个用户,并且位没有设置为除用户/组之外的任何人。但是,你安装模块的方式非常奇怪。 - Qix - MONICA WAS MISTREATED