LoginSignup
1
0

More than 3 years have passed since last update.

[Rails][React]Module not found: Error: Can't resolve '../bundles/HelloWorld/components/HelloWorld' 解決法

Last updated at Posted at 2020-08-08

起こったこと

既存の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 "."
..

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0