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

Rails/Webpacker运行异常求助:React项目资产预编译报错

Fix for Webpacker Compilation Failures with Rails/React & Webpack 3.3.0

Yep, I’ve hit this exact set of errors before— it boils down to a version mismatch between Webpacker and your installed Webpack version. Let’s walk through the solutions step by step:

Why This Happens

The deprecation warnings about Tapable.apply and Tapable.plugin plus the TypeError: dep.getResourceIdentifier is not a function error are all signs that your Webpacker gem/npm package is expecting a different Webpack version than the 3.3.0 you’re using.

Webpacker has strict version compatibility:

  • Webpacker 3.x works exclusively with Webpack 3.x
  • Webpacker 4+ requires Webpack 4.x or higher

Chances are your project has a newer Webpacker version installed that’s trying to use Webpack 4’s new Tapable hooks API, which doesn’t exist in Webpack 3.3.0.

Solution 1: Downgrade Webpacker to Match Webpack 3.3.0

If you want to keep using Webpack 3.3.0, adjust your dependencies to use a Webpacker version compatible with it:

  1. Update your Gemfile
    Change the webpacker gem line to target the 3.x series:

    gem 'webpacker', '~> 3.6'
    

    Then run:

    bundle install
    
  2. Update your npm dependencies
    Open your package.json and adjust the @rails/webpacker package to match the gem version (3.6.x):

    "@rails/webpacker": "~3.6.0"
    

    Then clean up old dependencies and reinstall:

    rm -rf node_modules package-lock.json # or yarn.lock if using Yarn
    npm install # or yarn install
    
  3. Verify and test
    Run the precompile command again to confirm the error is gone:

    rails assets:precompile RAILS_ENV=development
    

Solution 2: Upgrade Webpack to Match a Newer Webpacker (Optional)

If you’re open to upgrading Webpack to 4.x (which is more modern and supported), you can go this route instead:

  1. Update Webpacker to 4.x
    Modify your Gemfile:

    gem 'webpacker', '~> 4.0'
    

    Run bundle install.

  2. Upgrade Webpack and related packages
    In package.json, update Webpack to 4.x and ensure @rails/webpacker matches the gem version:

    "webpack": "~4.46.0",
    "@rails/webpacker": "~4.0"
    

    Clean and reinstall dependencies as before, then run the precompile command.

Extra Checks

If you still run into issues, double-check for other Webpack plugins in your package.json (like html-webpack-plugin) that might be using versions incompatible with your Webpack version. For Webpack 3, use plugin versions that explicitly support Webpack 3 (e.g., html-webpack-plugin@3.x).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:10:44