简体   繁体   English

由于这个“远程:sh:1:react-scripts:权限被拒绝错误”,正在努力将我的反应项目部署到 heroku

[英]Struggling to deploy my react project to heroku due to this `remote: sh: 1: react-scripts: Permission denied error`

I know that this answer has been asked in the past but I could not find a solution that pertains to my case.我知道过去曾有人问过这个答案,但我找不到适合我的情况的解决方案。 I've tried reinstalling my node_modules and my package-lock files, I've made sure that my.gitignore file properly excludes node_modules from the build.我已经尝试重新安装我的 node_modules 和我的包锁定文件,我确保 my.gitignore 文件正确地从构建中排除了 node_modules。 I'm not entirely sure what's going wrong when I try to deploy.当我尝试部署时,我不完全确定出了什么问题。 I've been working on this for a couple of days, trying to diagnose the issue to no avail.我已经为此工作了几天,试图诊断问题无济于事。 So I figured that I'd try here.所以我想我会在这里尝试。 I am using a server-client setup wherein I have separate package files for my server-side code and my client-side code.我正在使用服务器-客户端设置,其中我的服务器端代码和客户端代码有单独的 package 文件。 Here are the package files, my gitignore file and the error log from the heroku build session:以下是 package 文件、我的 gitignore 文件和来自 heroku 构建 session 的错误日志:

CLIENT PACKAGE.JSON客户 PACKAGE.JSON

{
  "name": "lang-flash",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:5000",
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "faker": "^4.1.0",
    "firebase": "^7.14.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.4.1",
    "stripe": "^8.39.2"
  },
  "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"
    ]
  }
}

SERVER PACKAGE.JSON服务器 PACKAGE.JSON

{
  "name": "lang-flash",
  "version": "1.0.0",
  "engines": {
    "node": "12.16.1",
    "npm": "6.13.4"
  },
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "client": "cd client && npm start",
    "server": "nodemon server.js",
    "build": "cd client && npm run build",
    "dev": "concurrently --kill-other-on-fail \"npm server\" \"npm client\"",
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/7ujh6/LangFlashApp.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/7ujh6/LangFlashApp.git/issues"
  },
  "devDependencies": {
    "concurrently": "^5.1.0",
    "nodemon": "^2.0.3"
  },
  "homepage": "https://github.com/7ujh6/LangFlashApp.git#readme",

  "dependencies": {
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "8.2.0",
    "express": "^4.17.1"
  }
}

GIT IGNORE FILE (in the server directory there isn't another git ignore file in the client directory) GIT IGNORE FILE(在服务器目录中没有另一个 git 在客户端目录中忽略文件)

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js


# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

HEROKU BUILD LOG HEROKU 构建日志

remote: -----> Build
remote:        Detected both "build" and "heroku-postbuild" scripts
remote:        Running heroku-postbuild
remote:
remote:        > lang-flash@1.0.0 heroku-postbuild /tmp/build_fcc986a2385b8c8783c9e93e3af2bd41
remote:        > cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build
remote:
remote:        audited 1748 packages in 13.332s
remote:
remote:        59 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 2 vulnerabilities (1 low, 1 high)
remote:          run `npm audit fix` to fix them, or `npm audit` for details
remote:        audited 1748 packages in 11.758s
remote:
remote:        59 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 2 vulnerabilities (1 low, 1 high)
remote:          run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote:        > lang-flash@0.1.0 build /tmp/build_fcc986a2385b8c8783c9e93e3af2bd41/client
remote:        > react-scripts build
remote:
remote: sh: 1: react-scripts: Permission denied
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! lang-flash@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the lang-flash@0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.jCutB/_logs/2020-05-14T22_31_39_955Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! lang-flash@1.0.0 heroku-postbuild: `cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the lang-flash@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.jCutB/_logs/2020-05-14T22_31_39_969Z-debug.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile React.js (create-react-app) multi app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to lang-flash.
remote:
To https://git.heroku.com/lang-flash.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/lang-flash.git'

Edit: I forgot to mention that it appears that my react scripts file has full permissions:编辑:我忘了提到我的反应脚本文件似乎具有完全权限: 在此处输入图像描述

hey have you found the answer yet?嘿,你找到答案了吗? I tried:我试过了:

if (process.env.NODE_ENV === "production"){

app.use(express.static(path.join(__dirname,"client", "build")))

app.get("*", (req, res) => {
    res.sendFile(path.join(__dirname,"client", "build", "index.html"));
});
}

and i have to npm install react-scripts in the server package.json file.我必须 npm 在服务器package.json文件中npm install react-scripts Also you have to put the "proxy": "http://localhost:5000" at the last curly brace in client package.json file.您还必须将"proxy": "http://localhost:5000"放在客户端package.json文件的最后一个花括号中。 That proxy is the server port.该代理是服务器端口。 It works for me!这个对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将我的应用程序(Node,React,Socketio)部署到Heroku会给我“ sh:1:react-scripts:权限被拒绝” - Attempting to deploy my app (Node, React, Socketio) to Heroku gives me “sh: 1: react-scripts: Permission denied” Heroku 构建失败 [sh: 1: react-scripts: Permission denied] - Heroku Build Fail [sh: 1: react-scripts: Permission denied] "npm run build" = "react-scripts: Permission denied" - "npm run build" = "react-scripts: Permission denied" 为什么“npm run build”会产生错误“react-scripts Permission denied”? - why does “npm run build” produce error “react-scripts Permission denied”? 我在创建 React 应用程序时出错,可能是由于我的 react-scripts 中的问题 - I am having an error creating a react app in my probably due to an issue in my react-scripts 尝试将 MERN 应用程序部署到 Now (zeit.co) 时出现“sh: react-scripts: command not found”错误 - Getting 'sh: react-scripts: command not found' error when trying to deploy MERN app to Now (zeit.co) 使用 react-scripts 指定项目路径 - Specifying project path with react-scripts 运行“npm run build”后“sh: 1: react-scripts: not found” - "sh: 1: react-scripts: not found" after running "npm run build" npm start throws sh: react-scripts: command not found - npm start throws sh: react-scripts: command not found 反应脚本无法识别 - react-scripts is not recognize
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM