【问题标题】:Heroku Build Fail [sh: 1: react-scripts: Permission denied]Heroku 构建失败 [sh: 1: react-scripts: Permission denied]
【发布时间】:2020-03-04 15:33:47
【问题描述】:
    ----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false

-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 12.x...
       Downloading and installing node 12.13.0...
       Using default npm version: 6.12.0

-----> Installing dependencies
       Prebuild detected (node_modules already exists)
       Rebuilding any native modules

       > nodemon@1.19.3 postinstall /tmp/build_33db88ab97938128199a401d17366aac/node_modules/nodemon
       > node bin/postinstall || exit 0

       Love nodemon? You can now support the project via the open collective:


          > https://opencollective.com/nodemon/donate

//REMOVED INSTALLATION TEXT HERE DUE TO CHAR LIMIT


-----> Build
       Running heroku-postbuild

       > website_setup@1.0.0 heroku-postbuild /tmp/build_33db88ab97938128199a401d17366aac
       > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client

       audited 905041 packages in 14.447s
       found 1 moderate severity vulnerability
         run `npm audit fix` to fix them, or `npm audit` for details

       > client@0.1.0 build /tmp/build_33db88ab97938128199a401d17366aac/client
       > react-scripts build

sh: 1: react-scripts: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.1egfD/_logs/2019-11-08T01_04_59_454Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! website_setup@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the website_setup@1.0.0 heroku-postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.1egfD/_logs/2019-11-08T01_04_59_470Z-debug.log
-----> Build failed


       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       Some possible problems:

       - node_modules checked into source control
         https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits

       - Node version not specified in package.json
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

       Love,
       Heroku

 !     Push rejected, failed to compile Node.js app.
 !     Push failed

简介:

我最近完成了 MERN 堆栈课程并去将我的构建推送到 Heroku,但遇到了上述错误。我首先认为这是一个 Visual Studio 权限错误,所以我以提升的权限运行 vs 代码。但是,这不起作用。

我尝试过但没有成功:

  1. 将 nodejs 脚本构建包添加到我的部署中
  2. 修改我的 package.json 以合并引擎,该引擎选择要运行的 node.js 版本
  3. 在脚本部分将 .js 扩展名添加到服务器末尾,认为这可能是一个简单的问题
  4. 仔细检查我的本地实例是否正常工作(确实如此)
  5. 赶紧把电脑扔出窗外(感觉还不错,但还是不行)

请参阅此链接以了解如何检查您的文件以获得正确的权限以及如何设置它们 (Updating file permissions with git-bash on Windows 7)

【问题讨论】:

  • 没有使用Heroku,但从日志中我认为chmod +x react-scripts在正确的目录中可以解决这个问题。
  • 你是对的,这是一个 chmod 错误。我已经删除了我之前的回复,谢谢!

标签: javascript node.js heroku


【解决方案1】:

我查看了您的 GitHub repo,这似乎是您的 .gitignore 文件中的一个简单错字:

node_module/ config/default.json

这应该是:

node_modules/ config/default.json

注意 node_modules 文件夹的名称,因此快速修复是编辑您的 .gitignore 文件并输入 wright 名称,然后运行以下命令:

  • git rm -r --cached node_modules
  • delete node_modules in root directory as well in client/
  • git commit -am 'ignore node_modules' 最后推送您的更改,这应该可以修复错误。

【讨论】:

  • 感谢您的回复,虽然它仍然无法正常工作,但我假设它只是另一个我必须弄清楚的简单错字。
  • 对不起,我忘记了您需要删除根目录中的 node_modules 以及客户端目录中的 node_modules,因为它之前被推送到 repo 并且它一定不存在,我编辑了答案,所以基本上这就是我首先注意到,我认为这是原因,但是当您设法修复错误时,请考虑发布您是如何做到的。
  • 我终于部署成功了,谢谢大家的帮助。没有另一个错字,我遇到了与我的 monogURI 相关的奇怪问题。解决方案是将mLab MongoDB作为免费插件安装在资源中,从“显示配置变量”下的设置中复制monogdb_uri,然后将新的monogURI粘贴到我的production.json文件中。
【解决方案2】:

sh: 1: react-scripts: Permission denied

所以这是一个权限问题。转到包含react-scripts 的正确路径并执行chmod +x react-scripts 将解决此问题。

【讨论】:

    【解决方案3】:

    检查你的 package.json => React-script-->

    step = 1==> "react-scripts": "(change_currend_version)"

    例如:“react-scripts”:“1.0.1”更改 ==>“react-scripts”:“3.4.3”

    步骤 = 2==> 安装 ==> npm i

    step = 3 ==> npm start

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 2019-12-14
      • 1970-01-01
      • 2021-03-04
      • 2020-09-17
      相关资源
      最近更新 更多