起こったこと
既存のRails プロジェクトにReact on Rails
を入れる。
rails generate react_on_rails:install
を実行するも
どうやら Webpackerのbuild が通らない。
ERROR in ./app/javascript/packs/hello-world-bundle.js
Module not found: Error: Can't resolve '../bundles/HelloWorld/components/HelloWorld' in '/home/vagrant/dev/rails-proj/app/javascript/packs'
@ ./app/javascript/packs/hello-world-bundle.js 2:0-69 5:14-24
...
解決法
どうやら別途、以下コマンドで設定ファイル生成が必要だったよう。
$ bin/rails webpacker:install:react
Copying babel.config.js to app root directory
force babel.config.js
Copying react example entry file to /home/vagrant/dev/rails/udr-tinder/app/javascript/packs
create app/javascript/packs/hello_react.jsx
Updating webpack paths to include .jsx file extension
insert config/webpacker.yml
Installing all react dependencies
run yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types from "."
..
参考