简体   繁体   中英

How can I use bootstrap in react with rails

I have tried using npm package reactstrap . My components:

import { Col, Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';

I'm getting the following error:

ExecJS::ProgramError at /dir/xyz
TypeError: require is not a function

The webpacker -gem is the way to go for react + rails, not sprockets, which is ok for jQuery style JS, but not for complicated ES6-based stacks.

From the README:

To use Webpacker with React, create a new Rails 5.1+ app using --webpack=react option:

 # Rails 5.1+ rails new myapp --webpack=react 

(or run bundle exec rails webpacker:install:react in a existing Rails app already setup with Webpacker).

The installer will add all relevant dependencies using Yarn, changes to the configuration files, and an example React component to your project in app/javascript/packs so that you can experiment with React right away.

Note that you'll be using yarn from then on, instead of npm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM