【问题标题】:path "/tmp/build_.../client/package.json" no such file or directory路径“/tmp/build_.../client/package.json”没有这样的文件或目录
【发布时间】:2020-05-31 03:24:57
【问题描述】:

我曾尝试在 heroku 上部署 MERN 堆栈应用程序。我遵循了 heroku 文档中给出的程序。但是,不知何故,我无法将应用程序部署到 heroku。

以下是我的 server.js 代码:

const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const path = require('path');

const items = require('./routes/api/items');

const app = express();

app.use(bodyParser.json());

const db = require('./config/keys').mongoURI;
mongoose
 .connect(db)
 .then(() => console.log('MongoDB Connected...'))
 .catch(err => console.log(err));


 app.use('/api/items', items);

 if (process.env.NODE_ENV === 'production') {
     app.use(express.static('client/build'));

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

 const port = process.env.PORT || 5000;
 app.listen(port, () => console.log(`Server started on port ${port}`));

以下是我在服务器文件夹中的 package.json 文件:

{
  "name": "mern_shopping_list",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "client-install" : "npm install --prefix client",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "dev" : "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build -- 
     prefix client"
},
"author": "",
"license": "ISC",
"dependencies": {
  "body-parser": "^1.19.0",
  "concurrently": "^5.1.0",
  "express": "^4.17.1",
  "mongoose": "^5.9.0"
},
"devDependencies": {
   "nodemon": "^2.0.2"
}
}

我得到的错误如下:

remote: -----> Build
remote:        Running heroku-postbuild
remote:
remote:        > mern_shopping_list@1.0.0 heroku-postbuild 
/tmp/build_6dafb80a10b85bd553ee344141227145
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix 
client
remote:
remote:        up to date in 0.284s
remote:        found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_6dafb80a10b85bd553ee344141227145/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open 
'/tmp/build_6dafb80a10b85bd553ee344141227145/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.2Rtdv/_logs/2020-02-15T15_35_57_654Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! mern_shopping_list@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install 
--prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the mern_shopping_list@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.2Rtdv/_logs/2020-02-15T15_35_57_666Z-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:        Some possible problems:
remote:
remote:        - node_modules checked into source control
remote:          https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
remote:
remote:        - Node version not specified in package.json
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to damp-anchorage-46764.
remote:
To https://git.heroku.com/damp-anchorage-46764.git
   ! [remote rejected] master -> master (pre-receive hook declined)
   error: failed to push some refs to 'https://git.heroku.com/damp-anchorage-46764.git'

我已经尝试了一些在线链接,但没有一个给出预期的结果。谁能建议我如何解决这个问题?

【问题讨论】:

  • 无法关注链接中的内容。你能解释一下@max630
  • 这是对我的编辑的解释;您真正的错误是服务器上的一些 npm 编译错误。你原来的标题是 git 报告它的方式。

标签: node.js git heroku npm mern


【解决方案1】:

cd 到你的 /client 删除 .git 文件夹

rm -rf .git

也可以通过这个命令重置 git:

git rm --cached . -rf

正如 Mina Amir 提到的,您的更改已经被客户端目录中的 git 跟踪,并且不会在您的提交中再次被服务器/主 git 跟踪

【讨论】:

  • 这太疯狂了。在部署到 Heroku 之前,我已经完成了这部分工作,但是在尝试部署到 Heroku 并遇到相同的错误后,我不得不再次实施您的解决方案。无论如何,它的工作,谢谢。
【解决方案2】:

当我复制我的项目并尝试部署时,我遇到了这个问题, 复制没有 node_modules 的后端和客户端 然后尝试在您的后端和客户端文件夹中 npm install, 然后尝试运行您的应用程序, 在这一点上,我遇到了一个名为“babel-jest”依赖项的错误,所以我安装了它并在 package.json 中手动将它的版本编辑为这个“^24.8.0”,然后我再次在根文件夹(后端)中运行 npm install ,然后我云恢复错误并运行应用程序,

在我开始部署过程之后,我按照以下步骤进行操作。

https://www.youtube.com/watch?v=qdoiwouykAg&list=PL8E3OP1AP-EneRlZoCIQ996os2DLegipk&index=3&t=873s

【讨论】:

    【解决方案3】:

    尝试从 /client 中删除 .git 文件夹,因为根目录中的主 .git 文件夹看不到 /client/package.json 并且不跟踪 /client 中的任何更改。 之后在根文件夹中从头开始提交所有内容

    【讨论】:

      猜你喜欢
      • 2020-09-14
      • 1970-01-01
      • 2014-07-09
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 2018-02-10
      • 2016-02-08
      • 2021-03-26
      相关资源
      最近更新 更多