Heroku 在部署时找不到我的文件,但它在本地工作

Heroku cannot find my file on deployment but it works locally

当我尝试使用 git push heroku master 部署到 Heroku 时,出现此错误:! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/afternoon-inlet-19669.git'

我找到了另一个 ,它帮助我摆脱了我的第一个错误。显然 GitHub 不会在提交时更新文件名中的大小写更改。所以,我意识到我有一个名为 spinner.js 的文件,它在我的本地机器上实际上被命名为 Spinner.js。

但是现在,我又报错了。

-----> 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):  12.x
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 12.x...
       Downloading and installing node 12.18.0...
       Using default npm version: 6.14.4
       
-----> Installing dependencies
       Installing node modules (package.json + package-lock)
       
       > nodemon@2.0.4 postinstall /tmp/build_94cb6f8d6d9567ec2a8f7d9ac35a0f48/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
       
       added 370 packages from 220 contributors and audited 371 packages in 12.257s
       
       12 packages are looking for funding
         run `npm fund` for details
       
       found 1 low severity vulnerability
         run `npm audit fix` to fix them, or `npm audit` for details
       
-----> Build
       Running heroku-postbuild
       
       > devconnector@1.0.0 heroku-postbuild /tmp/build_94cb6f8d6d9567ec2a8f7d9ac35a0f48
       > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
       
       
       > core-js@2.6.11 postinstall /tmp/build_94cb6f8d6d9567ec2a8f7d9ac35a0f48/client/node_modules/babel-runtime/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > core-js@3.6.5 postinstall /tmp/build_94cb6f8d6d9567ec2a8f7d9ac35a0f48/client/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > core-js-pure@3.6.5 postinstall /tmp/build_94cb6f8d6d9567ec2a8f7d9ac35a0f48/client/node_modules/core-js-pure
       > node -e "try{require('./postinstall')}catch(e){}"
       
       added 1686 packages from 803 contributors and audited 1690 packages in 41.105s
       
       59 packages are looking for funding
         run `npm fund` for details
       
       found 1 low severity vulnerability
         run `npm audit fix` to fix them, or `npm audit` for details
       
       > client@0.1.0 build /tmp/build_94cb6f8d6d9567ec2a8f7d9ac35a0f48/client
       > react-scripts build
       
       Creating an optimized production build...
       Failed to compile.
       
       ./src/components/dashboard/Dashboard.js
       Cannot find file '../layout/Spinner' in './src/components/dashboard'.
       
       
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
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.BfgW5/_logs/2020-06-17T17_40_23_134Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! devconnector@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the devconnector@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.BfgW5/_logs/2020-06-17T17_40_23_146Z-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
       
       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

这是我在 GitHub 上的项目的 link,知道为什么 Heroku 拒绝推送该应用程序吗? My Project Link

编辑

我相信解决方案是让 Github 意识到我的文件名已更改,它一定仍然认为文件名为 spinner.js.

UPDATE: 01/22/2021

您可以使用以下命令清除应用程序的构建缓存:

$ heroku plugins:install heroku-builds
$ heroku builds:cache:purge -a appname

缓存将在下一次部署时重建。如果您没有任何新代码要部署,您可以推送一个空提交。

$ git commit --allow-empty -m "Purge cache"
$ git push heroku master

其中 appname 替换为您要为其清除缓存的应用程序的名称。

OLD ANSWER for previous versions

您应该清理 Heroku 缓存:

heroku repo:purge_cache -a your_app_name

然后重试。

我遇到了同样的问题,我花了 100 个小时才弄明白。原来我在 .gitignore 中添加了一个强制文件名....

所以单个文件既没有上传到 Github,也没有上传到 Heroku。 Heroku 不会告诉我缺少哪个文件,但如果您尝试将应用程序上传到 DigitalOcean,DigitalOcean 会准确告诉您缺少哪个文件。 只需检查您的 .gitignore 文件,不要阻止节点模块以外的任何内容。甚至不要阻止 package-lock.json 文件上传。

如果这不是问题,则可能是区分大小写的问题,即与导入名称相比,文件名或组件名称的每个字母的大小写都不相同。不过可能是 .gitignore 的东西。