You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将React.js应用推送到Heroku时遭遇fsevents错误求助

Fixing fsevents Error When Deploying Your React App to Heroku

I’ve dealt with this exact fsevents headache before when deploying React apps to Heroku—since fsevents is a macOS-only dependency, Heroku’s Linux environment throws errors trying to install it, even when you mark it as optional. Let’s go through some solid fixes that should get your deployment back on track:

1. Use the Official create-react-app Heroku Buildpack

This buildpack is purpose-built for create-react-app projects and automatically handles platform-specific dependencies like fsevents (it skips them entirely on non-macOS systems). Here’s how to set it up:

  • Run this command in your project folder:
    heroku buildpacks:set mars/create-react-app
    
  • Commit any tweaks and push to Heroku again:
    git add .
    git commit -m "Switch to create-react-app buildpack"
    git push heroku main
    

2. Tell npm to Skip Optional Dependencies on Heroku

You can configure npm to ignore optional dependencies during the Heroku build by setting an environment variable:

  • Run this command to update your Heroku app’s config:
    heroku config:set NPM_CONFIG_NO_OPTIONAL=true
    
  • Push your code once more—Heroku will now install dependencies without attempting to set up fsevents.

3. Double-Check Your .gitignore and Git History

Even though you mentioned adding node_modules to .gitignore, it’s worth verifying a couple of things:

  • Ensure your .gitignore has a clean entry for node_modules/ (no typos or extra spaces that might be causing Git to ignore the rule)
  • If you accidentally committed node_modules to Git earlier, remove it with these commands:
    git rm -r --cached node_modules
    git add .
    git commit -m "Remove node_modules from Git tracking"
    

In most cases, using the create-react-app buildpack is the fastest fix since it handles edge cases like this out of the box. Give these steps a shot and your deployment should work smoothly.

内容的提问来源于stack exchange,提问作者Nischit Pradhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:23:51