将React.js应用推送到Heroku时遭遇fsevents错误求助
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
.gitignorehas a clean entry fornode_modules/(no typos or extra spaces that might be causing Git to ignore the rule) - If you accidentally committed
node_modulesto 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

