Heroku deploy with vitejs error H10(vite:not found)

pnwntuvh  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(114)

我试图在heroku中部署我的前端应用程序,但只有我得到的是错误。我正在修复错误,但我不知道该怎么办。
顺便说一下,我使用vitejs
我从Heroku日志中得到的错误

2021-07-30T11:30:06.680426+00:00 heroku[web.1]: Starting process with command `npm run dev`
2021-07-30T11:30:10.593125+00:00 app[web.1]: 
2021-07-30T11:30:10.593146+00:00 app[web.1]: > [email protected] dev
2021-07-30T11:30:10.593146+00:00 app[web.1]: > vite
2021-07-30T11:30:10.593146+00:00 app[web.1]: 
2021-07-30T11:30:10.614517+00:00 app[web.1]: sh: 1: vite: not found
2021-07-30T11:30:10.686497+00:00 heroku[web.1]: Process exited with status 127
2021-07-30T11:30:10.789749+00:00 heroku[web.1]: State changed from starting to crashed
2021-07-30T11:38:04.881585+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=example.herokuapp.com dyno= connect= service= status=503 bytes= protocol=https

字符串
我的package.json

{
  "name": "myapp",
  "description": "a really cool app",
  "version": "1.0.0",
  "engines": {
    "node": "<=16.x.x",
    "npm": "<=7.x.x"
  },
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  },
  "dependencies": {
    "react": "17.0.0",
    "react-dom": "17.0.0",
    "styled-components": "5.3.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react-refresh": "1.3.1",
    "vite": "2.4.2"
  },
  "peerDependencies": {
    "react-spring": "^9.2.4"
  }
}

4xy9mtcn

4xy9mtcn1#

解决方案:https://github.com/vitejs/vite/issues/1215
你必须取消设置npm env或yarn env的生产模式,如下所示:

heroku config:set NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false

字符串
如果你使用dokku:

dokku config:set my-app NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false

p8h8hvxi

p8h8hvxi2#

对于其他遇到这个问题的人,我能够使用serve包解决在heroku上部署静态vite/react应用程序的问题。显示的1答案对我不起作用,尽管它有助于解决错误,Vite然后部署它自己的开发服务器,而不是从Heroku提供服务。
从npm安装serve

npm i serve

字符串
将“vite”从devendencies移动到dependencies,现在应该看起来像这样:

"dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.15.0",
    "serve": "^14.2.1",
    "vite": "^4.4.5"
  },


更新package.json中的startheroku-postbuild脚本

"scripts": {
    "vite": "vite",
    "server": "nodemon server.cjs",
    "dev": "concurrently \"npm:server\" \"npm:vite\"",
    "build": "vite build",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview",
    "start": "serve -s dist",
    "heroku-postbuild": "npm run build"
  },


创建Procfile(无扩展名,大写'P')

web: npm run start


提交您的更改并推送到Heroku。

相关问题