尝试将带有顺风的 MERN 堆栈部署到 Heroku 时构建失败

Posted

技术标签:

【中文标题】尝试将带有顺风的 MERN 堆栈部署到 Heroku 时构建失败【英文标题】:Build failed when trying to deploy a MERN stack with tailwind onto Heroku 【发布时间】:2020-11-21 21:38:35 【问题描述】:

我正在尝试在 Heroku 上部署一个在前端使用 tailwind 的 MERN 堆栈应用程序,但它返回给我“构建失败”

这是 Heroku 的构建日志:

sh: 1: postcss: not found

npm ERR! code ELIFECYCLE

npm ERR! syscall spawn

npm ERR! file sh

npm ERR! errno ENOENT

npm ERR! web_page_react@0.1.0 build:tailwind: `postcss src/tailwind.css -o src/tailwind.generated.css`

npm ERR! spawn ENOENT

npm ERR! 

npm ERR! Failed at the web_page_react@0.1.0 build:tailwind 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.BI6XT/_logs/2020-07-31T16_43_03_360Z-debug.log

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! web_page_react@0.1.0 prebuild: `npm run build:tailwind`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the web_page_react@0.1.0 prebuild 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.BI6XT/_logs/2020-07-31T16_43_03_389Z-debug.log

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! web-items@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 web-items@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.BI6XT/_logs/2020-07-31T16_43_03_414Z-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
       
       Some possible problems:
       
       - Node version not specified in package.json
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
       
       Love,
       Heroku
       
!     Push rejected, failed to compile Node.js app.
 
!     Push failed

这是我的主要 package.json 中的脚本:


    "start": "node server",
    "server": "nodemon server",
    "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"
  

这是我的客户端 package.json 中的脚本:


    "build:tailwind": "postcss src/tailwind.css -o src/tailwind.generated.css",
    "watch:tailwind": "postcss -w src/tailwind.css -o src/tailwind.generated.css",
    "start": "run-p watch:tailwind start:react",
    "start:react": "react-scripts start",
    "prebuild": "npm run build:tailwind",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  

【问题讨论】:

我遇到了与项目设置完全相同的问题。你发现postcss问题了吗?谢谢。 【参考方案1】:

您的package.json 文件中似乎不存在postcss 模块。

你能给我看看你的package.json文件吗?

【讨论】:

我遇到了与项目设置完全相同的问题。你知道这个 postcss 问题是否已经解决了吗?

以上是关于尝试将带有顺风的 MERN 堆栈部署到 Heroku 时构建失败的主要内容,如果未能解决你的问题,请参考以下文章

在heroku中部署平均堆栈应用程序时出错

Craco 在 Heroku 中部署时无法构建反应应用程序

保存带有中断的文本区域,MERN 堆栈

如何将图像上传到 Cloudinary - MERN 堆栈

为啥我不能将一个 MERN 堆栈项目完全上传到 Github? (在其他地方找不到解决方案)

使用 Postman MERN 堆栈在发布请求上收到 404 错误