简体   繁体   English

将 React 项目部署到 Heroku 时出错:package.json 的“没有这样的文件或目录”

[英]Error when deploying React project to Heroku: “no such file or directory” for package.json

I am new to Heroku and am facing problems pushing my code to Heroku.我是 Heroku 的新手,并且在将我的代码推送到 Heroku 时遇到了问题。 I have a React/Node JS project.我有一个 React/Node JS 项目。 My folder structure is as follows:我的文件夹结构如下:

项目文件夹结构

I had my package.json file initially under backend folder but due to buildpack error I moved it to the root folder.我的 package.json 文件最初位于后端文件夹下,但由于 buildpack 错误,我将其移至根文件夹。

When I try pushing code to Heroku I get the following error:当我尝试将代码推送到 Heroku 时,出现以下错误:

\ProductInventoryApp> git push heroku HEAD:master

Enumerating objects: 110, done.
Counting objects: 100% (110/110), done.
Delta compression using up to 8 threads
Compressing objects: 100% (107/107), done.
Writing objects: 100% (110/110), 425.50 KiB | 2.73 MiB/s, done.
Total 110 (delta 38), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 12.x...
remote:        Downloading and installing node 12.14.1...
remote:        Using default npm version: 6.13.4
remote:
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        added 161 packages from 100 contributors and audited 304 packages in 7.815s
remote:
remote:        2 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 0 vulnerabilities
remote:
remote:
remote: -----> Build
remote:        Running heroku-postbuild
remote:
remote:        > ProductInventoryApp@1.0.0 heroku-postbuild /tmp/build_e7c760dc5d523bf5e1c2d0dc2b5b85cf
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:        up to date in 0.524s
remote:        found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_e7c760dc5d523bf5e1c2d0dc2b5b85cf/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_e7c760dc5d523bf5e1c2d0dc2b5b85cf/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.HV3Sb/_logs/2020-01-12T03_23_13_871Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! ProductInventoryApp@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 ProductInventoryApp@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.HV3Sb/_logs/2020-01-12T03_23_13_887Z-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 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 product-inventory-app.
remote:
To https://git.heroku.com/product-inventory-app.git
 **! [remote rejected] HEAD -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/product-inventory-app.git'**

I am not sure what's causing this.我不确定是什么原因造成的。 My package.json file is as follows:我的 package.json 文件如下:

{
  "name": "ProductInventoryApp",
  "version": "1.0.0",
  "description": "",
  "main": "backend/app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js",
    "client-install": "npm install --prefix client",
    "server": "nodemon app.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",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-validator": "^6.3.0",
    "mongodb": "^3.4.0",
    "mongoose": "^5.8.0",
    "uuid": "^3.3.3"
  },
  "devDependencies": {
    "concurrently": "^4.0.1"
  }
}

This is being caused by an issue with the heroku-postbuild script that you've defined.这是由您定义的heroku-postbuild脚本问题引起的。 Remove it from the package.json file and redeploy to Heroku to resolve the issue.package.json文件中删除它并重新部署到 Heroku 以解决问题。

try this.. it will help you out试试这个..它会帮助你

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend" "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"

basically, --prefix represents the path where react's package.json will exist... so, your react's package.json might be existed in frontend folder...基本上,--prefix 表示 react 的 package.json 将存在的路径......所以,你的 react 的 package.json 可能存在于前端文件夹中......

I've had the same problem until I've realised that my client/package.json was part of my .gitignore.我遇到了同样的问题,直到我意识到我的 client/package.json 是我的 .gitignore 的一部分。 If you are using Visual Studio, it does automatically add your package to it when creating gitignore.如果您使用的是 Visual Studio,它会在创建 gitignore 时自动将您的包添加到其中。

暂无
暂无

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

相关问题 Heroku部署应用程序时出错:无法解析package.json - Heroku error deploying app: unable to parse package.json Heroku 没有为 react package.json 获取 PORT - Heroku is not getting PORT for react package.json 在 Heroku 上部署之前,我应该在 MERN 应用程序的 package.json 文件的脚本中进行哪些更改? - What changes should I make in the script of the package.json file of a MERN app before deploying on Heroku? Docker 错误:没有那个文件或目录,打开'/package.json' - Docker error: no such file or directory, open '/package.json' ENOENT错误 - 没有这样的文件或目录,打开'package.json',从Electron Builder / Packager打包时 - ENOENT Error - no such file or directory, open 'package.json', when packaged from Electron Builder/Packager both 推送到 Heroku 时出现 package.json/package-lock.json 同步错误 - Getting package.json/package-lock.json sync error when pushing to Heroku 错误说没有package.json,但它在当前目录中 - Error says no package.json, but it is in current directory Node/NPM 正在我的主目录而不是项目目录中更新 package.json 和 package-lock.json 文件 - Node/NPM is updating package.json and package-lock.json file in my home directory instead of project directory 如何在package.json中的项目目录中为gulp文件创建路径 - How to make a path for gulp file in project's directory in package.json 如何在没有 package.json 文件的情况下运行 JavaScript 项目,从而在运行时出错? - How do I run a JavaScript project with no package.json file present, which therefore gives error when running it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM