Rails + Webpacker + React.js / Cannot find module
Asked Answered
S

1

12

I'm learning React.js with Rails 4.2 (to prepare to work on it) but I have a lot of errors in my console.

So I'm using React 16.8 (with react-rails gem) + Rails 4.2 + Webpacker 4.0.2

My folders structure:

app
 |
 javascript
    |
    packs
      |
      application.js
      server_rendering.js
      components
       |
       main.js.jsx
       header.js.jsx
       body.js.jsx
       new_item.js.jsx
       all_items.js.jsx

In my application layout, I added = javascript_pack_tag('application') In my index view, I have = react_component('Main')

But I have these errors:

errors This is my application.js :

var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

main.js.jsx :

var Main = React.createClass({
  render() {
    return (
      <div>
        <Header />
        <Body />
      </div>
    );
  }
});

I tried to add import React from ‘react’ in main.js.jsx but I still have the errors.

this is the first time I use React, I do not know where to look... Any help would be very appreciate

Thanks

Samella answered 28/4, 2019 at 15:7 Comment(2)
Have you found a solution to this?Aragonite
My solution was to never approach React again lolSamella
H
0

You might want to try upgrading to https://github.com/shakacode/shakapacker

Hello answered 8/7, 2023 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.