путь "/tmp/build_.../client/package.json" нет такого файла или каталога - PullRequest
1 голос
/ 15 февраля 2020

Я пытался развернуть приложение стека MERN на heroku. Я следовал процедуре, указанной в документации к героку. Но я почему-то не могу развернуть приложение на heroku.

Ниже указан мой сервер. 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}`));

Ниже приведен мой пакет. 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'

Я пробовал некоторые ссылки в Интернете, но ни одна из них не давала желаемого результата. Кто-нибудь может подсказать, как это исправить?

...