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

Heroku部署React服务端渲染应用报错:找不到webpack-assets.json模块

Hey Jose, sorry to hear you're stuck with this Heroku deployment hiccup! Let's go through some practical fixes for the Cannot find module ../public/webpack-assets.json error you're facing with React-Cool-Starter:

1. Verify webpack-assets.json exists and is committed to Git

  • First, run your local build command (like npm run build) and check if public/webpack-assets.json is actually generated. If it's missing locally, your build script might have an issue—double-check your Webpack or React-Cool-Starter config to ensure this file is output correctly.
  • Open your .gitignore file and make sure it isn't excluding webpack-assets.json or the entire public directory. Heroku deploys from your Git repo, so if the file isn't committed, it won't be available on the server. Remove any unwanted ignore rules, commit the file, and redeploy.

2. Fix path resolution for webpack-assets.json

  • Relative paths can behave differently on Heroku compared to your local environment. Try replacing the relative import with an absolute path using Node's path module. For example:
    const assets = require(path.resolve(__dirname, '../public/webpack-assets.json'));
    
  • Double-check your webpack-isomorphic-tools config file. Ensure the assets field points to the correct location of webpack-assets.json, and that any path-related settings align with where the file is generated during the build.

3. Ensure Heroku runs your build script

  • Heroku might not automatically trigger your build process. Add a heroku-postbuild script to your package.json to force the build during deployment:
    "scripts": {
      "build": "your-existing-build-command",
      "heroku-postbuild": "npm run build"
    }
    
  • Check your Heroku build logs (run heroku logs --tail -a your-app-name) to confirm the build step runs successfully and generates webpack-assets.json. Look for any errors during the build that might be preventing the file from being created.

4. Clear Heroku's cache and redeploy

  • Old cached files can sometimes cause issues. Purge the cache and push a fresh deployment with these commands:
    heroku plugins:install heroku-repo
    heroku repo:purge_cache -a your-app-name
    git commit --allow-empty -m "Purge Heroku cache"
    git push heroku main
    

内容的提问来源于stack exchange,提问作者Jose Ferran

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:23:23